因此,应该假设这是要检查看看谁对我发送给所有人的消息有反应!但是它有一个错误list index out of range
这是代码
@client.command()
async def public(ctx, winners: int, time: int, link:str, *, prize:str):
for guild in client.guilds:
for channel in guild.channels:
if(channel.name == '୨?୧┊giveaway'):
embed = discord.Embed(
title = f"**Giving Away {prize}**",
description = f"React with ? to enter! \n **{winners}** winner \n \n ? Must be in **[this server]({link})** to enter!", color=0xf9c900)
msg = await channel.send(embed=embed)
await msg.add_reaction('?')
await asyncio.sleep(1)
await asyncio.sleep(time)
for guild in client.guilds:
for channel in guild.channels:
if(channel.name == '୨?୧┊giveaway'):
reactors = await msg.reactions[0].users().flatten()
winnersgoal = random.choice(reactors)
winnermessage = await channel.send(f"Hey {winnersgoal}! You have won {prize}! Please come and collect them [here](https://discord.gg/)")
答案 0 :(得分:0)
您需要再次获取消息及其ID,以获取消息的更新状态。
@client.command()
async def public(ctx, winners: int, time: int, link:str, *, prize:str):
channel = discord.utils.get(client.get_all_channels(), name='୨?୧┊giveaway')
if channel:
embed = discord.Embed(
title = f"**Giving Away {prize}**",
description = f"React with ? to enter! \n **{winners}** winner \n \n ? Must be in **[this server]({link})** to enter!", color=0xf9c900)
msg = await channel.send(embed=embed)
await msg.add_reaction('?')
await asyncio.sleep(1)
await asyncio.sleep(time)
msg = await channel.fetch_message(msg.id)
reactors = await msg.reactions[0].users().flatten()
winnersgoal = random.choice(reactors)
winnermessage = await channel.send(f"Hey {winnersgoal}! You have won {prize}! Please come and collect them [here](https://discord.gg/)")
else:
await ctx.send("Channel Not Found")