python - 如何在 Discord.py 中制作赠品命令?
问题描述
因此,我尝试将此代码用于赠品命令,但由于某种原因,它从未显示用户输入的反应。我尝试更改赠品图标,也许重新运行代码,但没有运气。
@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!"
)
有人知道怎么修这个东西吗?
解决方案
我注意到您将“my.msg”作为变量名,官方 python 文档不允许您使用名称中的点创建变量,因为这是保留关键字。我可以建议改为:
my_msg = await ctx.send(embed=embed)
await my_msg.add_reaction("")
推荐阅读
- gradle - Unity Gradle Build Fail: processReleaseManifest 由于属性冲突
- google-cloud-platform - Redis 是否可以从其 RDB 备份过程中使用多个内核中受益?
- flutter - 在 Flutter 上,我想从硬盘驱动器获取图像并随机显示
- pandas-groupby - 用groupby中的2个变量计算滚动总和
- rust - 如何在函数中调用 FLTK 代码?
- json - 如何将虚拟数据添加到嵌套的 JSON 结构
- docker - 防止在 docker 镜像标签中插入端口号
- java - 使用 Enum 存储常量并在多个类中使用这些常量
- javascript - 有没有办法使用文件系统访问 API 以编程方式设置默认目录
- python-3.x - Gurobi 的速度比 CBC 求解器慢(使用 PuLP)?