对不起我的英语,我是法语:P
我正在用python做一个不和谐的机器人(我是python的初学者),并且正在一步一步地做。现在,我希望机器人在用户点击表情符号时做出反应。我使用了3个自定义表情符号,它不起作用:(
对于测试,我尝试了:slight_smile:,并且效果很好。我不知道我做错了还是自定义表情符号无法做到这一点...
您能帮我找出代码中出了什么问题吗? :)
@bot.command(name="mm",help="permet de créer une invit mm+ avec !mm clé niveau heure. Exemple: !mm Boralus +14 21h00")
async def mm(ctx, arg, arg2, arg3):
embed = discord.Embed(title="Inscription pour {} en {} vers {}" .format(arg, arg2, arg3), description="Composition du groupe") #,color=Hex code
embed.add_field(name="Tank", value="<:tank:761252435720667157>tank\n", inline = False)
embed.add_field(name="Heal", value="<:heal:761252937548169246>heal\n", inline = False)
embed.add_field(name="Dps1", value="<:dps:761252937066217512>dps1\n", inline = False)
embed.add_field(name="Dps2", value="<:dps:761252937066217512>dps2\n", inline = False)
embed.add_field(name="Dps3", value="<:dps:761252937066217512>dps3\n", inline = False)
# On ajoute les emojis
sent = await ctx.send(embed=embed)
emojis=['<:tank:761252435720667157>', '<:heal:761252937548169246>', '<:dps:761252937066217512>', '?' ]
for emoji in emojis:
await sent.add_reaction(emoji)
# On réagit aux emoji
@bot.event
async def on_reaction_add(reaction, user):
message = reaction.message
emoji = reaction.emoji
tank = "<:tank:761252435720667157>"
heal = "<:heal:761252937548169246>"
dps = "<:dps:761252937066217512>"
test = "?"
if user.bot:
return
if emoji == tank:
print ("testtank")
elif emoji == heal:
print ("testheal")
elif emoji == dps:
print ("testdps")
elif emoji == test:
print ("smiley")
else:
return
答案 0 :(得分:0)
在自定义表情符号中,您应该在公会的聊天中进行\'emoji'
来获得其ID。如我所见,您获得了ID,但是忘记了在开头和结尾添加<>
。
代替
tank = ":tank:761252435720667157"
heal = ":heal:761252937548169246"
dps = ":dps:761252937066217512"
您应该使用
tank = "<:tank:761252435720667157>"
heal = "<:heal:761252937548169246>"
dps = "<:dps:761252937066217512>"
也代替
emojis=[':tank:761252435720667157', ':heal:761252937548169246', ':dps:761252937066217512', '?' ]
您应该使用
emojis=['<:tank:761252435720667157>', '<:heal:761252937548169246>', '<:dps:761252937066217512>', '?' ]
这将解决您的问题。 编辑
使用if
语句时,请执行if str(emoji) == tank
,if str(emoji) == heal
,emoji
返回discord.Reaction
类。如果这样做,它将起作用。
答案 1 :(得分:0)
您应该让机器人获取相应的表情对象。这样,您就可以将反应表情与坦克,治愈,dps等表情相互比较。这是我的解决方案,其中还包括命令内部的反应检查。如果您有任何后续问题,请随时提出。我很乐意提供帮助。
.mat-card-title {
margin-left: -16px;
}