Alpha
Alpha

Reputation: 329

How to check if a message.author is a bot in discord.py

this is my on_message_edit event for my logs. Although it works fine I was wondering how could I make it not trigger when a bot edits a message.

 @commands.Cog.listener()
 async def on_message_edit(self, before, after):
        channel1 = await self.bot.logs.find(before.guild.id)  # this is for my db
        channel = channel1["channel"]  # also for my db
        logs = self.bot.get_channel(channel)  # also for my db
        if before.content.author == self.bot:
            return
        if before.content != after.content:
            embed = discord.Embed(title="Message edited", color=0xe74c3c)
            embed.add_field(name="Previous message", value=f"{before.content}", inline=False)
            embed.add_field(name="New message", value=f"{after.content}", inline=False)
            await logs.send(embed=embed)

Thank you for your time :)

Upvotes: 1

Views: 4161

Answers (1)

Nurqm
Nurqm

Reputation: 4743

You can use discord.Member.bot. It returns True if a member is bot.

@commands.Cog.listener()
async def on_message_edit(self, before, after):
    if before.author.bot:
        return
    ...

Reference

Upvotes: 2

Related Questions