大家好,我遇到了一个问题,我尝试用 python 学习机器人以解决不和谐问题。 我尝试让机器人可以修改消息并登录消息,所有人都做出反应并删除做出其他反应的人
我不明白我该怎么办
我把这个代码:
我不知道如何自动删除反应并使用人名更改变量,谢谢
my_secret = os.environ['TOKEN']
client = discord.Client()
var1 = "placeholder"
var2 = "placeholder"
@client.event
async def on_message(message):
if message.content.startswith('!hello'):
#titolo= input('Inserisci un titolo') ricorda di cambiare title sotto
embedVar = discord.Embed(title='Staff Disponibile', description="Controlla chi dello staff è in servizio per aiutarti o per farti la whitelist", color=0x00ff00)
embedVar.add_field(name=var1 , value="hi", inline=False)
embedVar.add_field(name=var2 , value="hi2", inline=False)
mess = await message.channel.send(embed=embedVar)
await mess.add_reaction('✅')
await mess.add_reaction('❌')
#await message.clear_reaction("✅")
client.run (my_secret)
答案 0 :(得分:0)
您需要有另一个监听器来添加反应,因为当命令运行时,它会运行一次并且无法监听反应添加。 无论如何,实际代码在这里:
my_secret = os.environ['TOKEN']
client = discord.Client()
var1 = "placeholder"
var2 = "placeholder"
@client.event
async def on_message(message):
if message.content.startswith('!hello'):
embedVar = discord.Embed(title='Staff Disponibile', description="Controlla chi dello staff è in servizio per aiutarti o per farti la whitelist", color=0x00ff00)
embedVar.add_field(name=var1 , value="hi", inline=False)
embedVar.add_field(name=var2 , value="hi2", inline=False)
mess = await message.channel.send(embed=embedVar)
await mess.add_reaction('✅')
await mess.add_reaction('❌')
@client.event
async def on_reaction_add(reaction, user):
#idk if this part is needed. Just put it to make sure the message and channel are fetched.
if user.id == client.user.id:
return;
channel = await client.fetch_channel(reaction.message.channel.id) # Making sure you have the channel in cache
message = await channel.fetch_message(reaction.message.id)
await reaction.remove(user) #reaction removes everytime any one clicked
if reaction.emoji == "✅":
var1 = user.display_name #or whatever the variable you need to replace.
embedVar = discord.Embed(title='Staff Disponibile', description="Controlla chi dello staff è in servizio per aiutarti o per farti la whitelist", color=0x00ff00)
embedVar.add_field(name=var1 , value="hi", inline=False)
embedVar.add_field(name=var2 , value="hi2", inline=False)
await message.edit(embed=embedVar)
client.run (my_secret)
这应该在我测试时有效。 如果它不发表评论,我会尽力帮助你!
提示:按此答案旁边的灰色复选标记接受它,并支持我!