所以我尝试使用此代码作为赠品命令,但由于某种原因,它从未显示用户输入的反应。我尝试更改赠品图标,也许重新运行代码,但没有运气。
@client.command()
@commands.has_role("Admin")
async def gstart(ctx, mins: int, *, prize: str):
embed = discord.Embed(title="Giveaway!",
description=f"{prize}",
color=ctx.author.color)
end = datetime.datetime.utcnow() + datetime.timedelta(seconds=mins * 60)
embed.add_field(name="Ends At:", value=f"{end} UTC")
my.msg = await ctx.send(embed=embed)
await my.msg.add_reaction("?")
await asyncio.sleep(mins)
new_msg = await ctx.channel.fetch_message(my_msg.id)
users = await new_msg.reactions[0].users().flatten()
users.pop(users.index(client.user))
winner = random.choice(users)
await ctx.send(f"Congratulations! {winner.mention} won {prize}!")
@client.command()
@commands.has_permissions(kick_members=True)
async def reroll(ctx, channel: discord.TextChannel, id_: int):
try:
new_msg = await channel.fetch_message(id_)
except:
await ctx.send(
"The ID that was entered was incorrect, make sure you have entered the correct giveaway message ID."
)
users = await new_msg.reactions[0].users().flatten()
users.pop(users.index(client.user))
winner = random.choice(users)
await channel.send(
f"Congratulations the new winner is: {winner.mention} for the giveaway rerolled!"
)
有人知道如何解决这个问题吗?
答案 0 :(得分:1)
我注意到你把“my.msg”作为你的变量名,官方的python文档不允许你在名称中创建带有点的变量,因为这是一个保留关键字。我是否建议改为将其更改为:
my_msg = await ctx.send(embed=embed)
await my_msg.add_reaction("?")