【问题标题】:discord.py bot edit snipe command that snipes the recently edited messagediscord.py bot edit snipe 命令,用于狙击最近编辑的消息
【发布时间】:2021-04-21 02:37:50
【问题描述】:

我一直在研究一个不和谐的机器人,我能够创建狙击命令,很好地狙击最近删除的消息,但现在我正在尝试对其进行编程,以便能够编辑狙击,即狙击最近编辑消息

这是我的狙击删除消息代码

    async def on_ready(self):
        print('Snipe commands are working')


    @commands.Cog.listener()
    async def on_message_delete(self, message):

        global snipe_message_content
        global snipe_message_author
        global snipe_message_id
        global snipe_message_channel
        global snipe_message_author_avatar
        global a
        global b

        snipe_message_content = message.content
        snipe_message_author = message.author.id
        snipe_message_id = message.id
        snipe_message_channel = message.channel
        snipe_message_author_avatar = message.author.avatar_url
        a = message.author.name
        b = message.author.discriminator
        
        if (snipe_message_author in botsid):
            m == 1
        else:
            embed = discord.Embed(description=f"????️ **Message sent by** <@!{snipe_message_author}> **deleted in** {message.channel.mention} \n  \n {snipe_message_content}")
            embed.set_author(name= f"‎‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎{message.author.name}#{message.author.discriminator}")
            channel = self.client.get_channel(795726497922809947)
            await channel.send(embed=embed)

【问题讨论】:

标签: python discord discord.py discord.py-rewrite


【解决方案1】:

您可以通过使用 on_message_edit 和在编辑消息之前使用 message_before 来简单地实现此目的。下面是一个例子

async def on_message_edit(message_before, message_after):
      
        author = message_before.author
        guild = message_before.guild.name
        channel = message_before.channel


        await channel.send(f"""
   
        Original Message
        {message_before.content}

        Updated Message
        {message_after.content}""")


从这里,您可以复制上面所做的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-30
    • 2019-03-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 2020-11-23
    • 2021-07-30
    • 2023-03-31
    相关资源
    最近更新 更多