我正在研究一个命令,如果你对机器人做出同意反应,它将发送一个 nuke gif.这很好用,但是如果您选择其他选项或超时,我无法让机器人回答不同.我当前的代码如下.感谢您的帮助
I was working on a command which will send a nuke gif if you react bot with an agree reaction. This works fine however I cant make bot answer diffrently if you choose other option or timeout. My current code is bellow. Thanks for your help
async def nuke(ctx):
yas = '✔️'
nay = '❌'
message = await ctx.send("Are you sure that you want to use your nukes?")
await message.add_reaction(yas)
await message.add_reaction(nay)
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) == '✔️'
await bot.wait_for('reaction_add', timeout=60.0, check=check)
embed = discord.Embed(title="Code: 759245 Activated. Destruction of Channel started")
embed.set_image(url="https://i.gifer.com/3Tt5.gif")
await ctx.send(embed=embed)
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) == '❌'
await bot.wait_for('reaction_add', timeout=60.0, check=check)
await ctx.send("Cancelled")```
代码从上到下,这意味着您的代码现在要执行的操作如下:
Code goes top to bottom, meaning that what your code will do now is the following:
'✔️'3Tt5'❌'您将要编写 one 检查以检查是否使用了 任何 个可能的反应,然后以不同的方式处理所有这些反应.
You're gonna want to write one check that checks if any of the possible reactions was used, and then handle all of them differently.
yas = '✔️'
nay = '❌'
valid_reactions = ['✔️', '❌']
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in valid_reactions
reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
if str(reaction.emoji) == yas:
embed = # code to create the embed
return await ctx.send(embed=embed)
# there's only two reactions, so if the above function didn't return, it means the second reaction (nay) was used instead
await ctx.send("Cancelled")
这篇关于使用 discord.py 进行反应检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
python:不同包下同名的两个模块和类python: Two modules and classes with the same name under different packages(python:不同包下同名的两个模块和类)
配置 Python 以使用站点包的其他位置Configuring Python to use additional locations for site-packages(配置 Python 以使用站点包的其他位置)
如何在不重复导入顶级名称的情况下构造python包How to structure python packages without repeating top level name for import(如何在不重复导入顶级名称的情况下构造python包)
在 OpenShift 上安装 python 包Install python packages on OpenShift(在 OpenShift 上安装 python 包)
如何刷新 sys.path?How to refresh sys.path?(如何刷新 sys.path?)
分发带有已编译动态共享库的 Python 包Distribute a Python package with a compiled dynamic shared library(分发带有已编译动态共享库的 Python 包)