我正在尝试创建一个选择屏幕,其中有两个选项(两个反应),用户可以对其进行反应,然后漫游器会自动选择用户的反应
我尝试过比较
反应!=“?”或反应!=“”✋
还尝试了:
反应!= u“ \ U0001F44C”或反应!= u“ \ u270B”
使用unicode。
还尝试了与react.emoji,str(reaction / reaction.emoji)相同的代码。
还尝试比较表情符号的ID,但react.emoji.id引发异常,表示react.emoji是一个str且字符串没有id
(因为idk为什么它返回一个str而不是一个emoji表情对象)
我已经阅读了文档,并说它支持!=操作,但是我不知道要比较什么
@bot.event
async def on_reaction_add(reaction,user):
print(reaction) #It prints the two emojis on my console (? and ✋)
if user.bot:
print('I am a bot')
return
if reaction != "?" or reaction != "✋":
print('Did not found the emoji')
return
else:
print('Found the emoji')
#And then some code wich will decide if the user that reacted is valid and what to do with it
#The embed the user have to react to if this helps
embed = discord.Embed(title = 'VS',color=0x00fff5)
embed.set_author(name = message.author.name,icon_url=message.author.avatar_url)
embed.set_footer(text = message.mentions[0].name , icon_url = mensaje.mentions[0].avatar_url)
response = await message.channel.send(embed = embed)
await response.add_reaction("?") #OK emoji
await response.add_reaction("✋") #STOP emoji
我希望机器人能够识别表情符号,但不知道如何
答案 0 :(得分:0)
TL; DR
or
的{{1}}切换为and
(请参阅不和谐的docs中的示例)说明:
De Morgan's Laws会这样说
str(reaction.emoji)
与写作
相同if str(reaction.emoji) != "?" or str(reaction.emoji) != "✋":
并且由于反应不能同时是OK 和 STOP,因此if not (str(reaction.emoji) == "?" and str(reaction.emoji) == "✋"):
语句总是返回if
且“未找到表情符号”始终会打印。
类似
True
会工作的。
编辑:恕我直言,一种更具可读性的解决方案是检查set中表情符号的存在。
if str(reaction.emoji) != "?" and str(reaction.emoji) != "✋":
print('Did not found the emoji')
return
else:
print('Found the emoji')