【问题标题】:bot discord if someone click reaction change message and delete reaction discord.py如果有人单击反应更改消息并删除反应 discord.py,则机器人不和谐
【发布时间】:2021-08-09 03:37:38
【问题描述】:

大家好,我有一个问题,我尝试用 python 学习 bot 以解决不和谐。 我尝试让机器人可以修改消息并登录消息,所有的人都发表了反应并删除了其他人的反应

我不明白我该怎么做

我把这段代码:

我不知道如何使自动删除反应并用人的名字更改变量,谢谢

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)

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    您需要为响应添加设置另一个侦听器,因为当命令运行时,它会运行一次并且无法侦听响应添加。 无论如何,实际代码在这里:

    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)
    
    

    这在我测试时应该可以工作。 如果它没有发表评论,我会尽力帮助你!

    提示:按此答案旁边的灰色复选标记以接受它,并支持我!

    【讨论】:

      猜你喜欢
      • 2021-11-03
      • 2018-05-02
      • 2020-12-06
      • 2021-11-14
      • 2020-06-29
      • 2020-09-03
      • 2021-11-28
      • 1970-01-01
      • 2020-08-02
      相关资源
      最近更新 更多