問題描述
我已經(jīng)寫了一個命令.當您執(zhí)行此命令時,機器人會向特定頻道發(fā)送消息.他對此消息添加了一個反應(yīng)(順便說一句嵌入).到目前為止.但是現(xiàn)在,當有人點擊這個反應(yīng)時,我希望機器人做出回應(yīng).在這種情況下,他應(yīng)該向特定頻道發(fā)送消息.但這不起作用.也沒有錯誤碼,應(yīng)該是可以的,只是他沒有發(fā)消息.
I have already written a command. When you execute this command, the bot sends a message to a specific channel. He adds a reaction to this message (an embed by the way). That goes so far. But now, when someone clicks on this reaction, I wanted the bot to respond. In this case, he should send a message to a specific channel. But that doesn't work. There is also no error code, which is supposed to mean that it works, only he doesn't send a message.
@bot.command()
async def buy(ctx, choice):
channel = bot.get_channel(705836078082424914)
user = ctx.message.author
vcrole1 = get(user.guild.roles, id=703562188224331777)
messagechannel = ctx.message.channel.id
if ctx.message.channel.id == 705146663135871106:
if choice == '1':
if any(role.id == 703562188224331777 for role in ctx.message.author.roles):
await user.remove_roles(vcrole1)
await ctx.send(
"not important message")
messtag1 = await channel.send('not important')
await messtag1.delete(delay=None)
embed = discord.Embed(color=0xe02522, title='not important title', description=
'not important description')
embed.set_footer(text='not important text')
embed.timestamp = datetime.datetime.utcnow()
mess1 = await channel.send(embed=embed)
await mess1.add_reaction('<a:check:674039577882918931>')
def check(reaction, user):
return reaction.message == mess1 and str(reaction.emoji) == '<a:check:674039577882918931>'
await bot.wait_for('reaction_add', check=check)
channeldone = bot.get_channel(705836078082424914)
await channeldone.send('test')
沒有錯誤消息.
推薦答案
看起來你的 reaction.message == mess1
條件返回 False
,我可以不要把它縮小到為什么會發(fā)生這種情況,但如果我這樣做了,我會編輯它.
It looks as though your reaction.message == mess1
condition is returning False
, and I can't narrow it down as to why that's happening, but I'll edit this if I do.
解決這個問題的一種方法是評估消息的 ID:
A way to overcome this would be to evaluate the IDs of the messages:
return reaction.message.id == mess1.id and str(reaction.emoji) == '<a:check:674039577882918931>'
當機器人做出反應(yīng)時,這將評估為 True
,所以我建議添加另一個條件來檢查用戶是否做出反應(yīng),如果這是您希望用戶執(zhí)行的操作:
And this will evaluate to True
when the bot reacts, so I'd recommend adding another condition to check that the user reacted, if that is what you want the user to do:
return .... and user == ctx.author
<小時>
參考資料:
Message.id
discord.Member
這篇關(guān)于discord.py “wait_for"命令中的反應(yīng)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!