【发布时间】:2021-03-12 22:11:51
【问题描述】:
我正在制作一个使用 DM 的 Discord.py 机器人。我有一个命令,机器人会向您发送消息,要求您对您尝试执行的操作做出反应。问题是当用户添加它不起作用的反应时。
这是我目前所拥有的
@client.command()
async def suggest(ctx):
embed = discord.Embed(
title = 'What kind of suggestion are you making?',
description = '<:Yes:755187983585509517> Car Suggestion\n<:Maybe:755187983623258123> Job Suggestion\n<:No:755187984067854367> Other Suggestion Type',
colour = discord.Colour.green()
)
await ctx.message.delete()
await ctx.send(f'{ctx.message.author.mention} Please check your DMs to continue!')
embed.set_footer(text='Pembroke Pines Bot - Made By: parker02311')
msg = await ctx.author.send(embed=embed)
await msg.add_reaction('<:Yes:755187983585509517>')
await msg.add_reaction('<:Maybe:755187983623258123>')
await msg.add_reaction('<:No:755187984067854367>')
def check(reaction, user):
return user == msg.author and str(reaction.emoji) == '<:Yes:755187983585509517>'
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await ctx.author.send("Timed out")
else:
embed = discord.Embed(
title = 'Car Suggestion',
description = 'What is your username?',
colour = discord.Colour.green()
)
embed.set_footer(text='Pembroke Pines Bot - Made By: parker02311')
await ctx.author.send(embed=embed)
def check(m):
return m.content
msg = await client.wait_for('message', check=check)
await ctx.author.send(f'Okay, your username is: **{msg}**')
embed = discord.Embed(
title = 'Car Suggestion',
description = 'What is the car model?',
colour = discord.Colour.green()
)
embed.set_footer(text='Pembroke Pines Bot - Made By: parker02311')
await ctx.author.send(embed=embed)
msg = await client.wait_for('message', check=check)
await ctx.author.send(f'Okay, the model is: **{msg}**')
#channel = client.get_channel(734882692537253900)
embed = discord.Embed(
description = f'{ctx.message.author.mention} **made a suggestion\nChannel:** {ctx.message.channel}\n**Message Content:** {ctx.message.content}',
colour = discord.Colour.red()
)
embed.set_footer(text='Pembroke Pines Bot - Made By: parker02311')
embed.set_author(name=ctx.message.author)
await logschannel.send(embed=embed)
这几乎直接来自 discord.py 文档。 https://discordpy.readthedocs.io/en/latest/api.html#discord.Client.wait_for
【问题讨论】:
-
您的
@client.event或@bot.command等在哪里? -
我会为完整的命令编辑它我刚刚给出了重要的部分,因为完整的命令很长
-
@KarlKnechtel 你去那里有完整的代码
-
好的,当你说它“不起作用”时 - 是否有错误消息?有什么可观察到的事情发生吗?
-
@KarlKnechtel 不,什么都没有发生,没有错误,没有结果
标签: python discord.py