How can make my Python Discord bot I check if a message was sent by the bot itself?

The message class contains information on the message's author, which you can utilize to determine whether or not to respond to the message. author is a Member object (or its superclass User if the channel is private), which has an id property but also supports direct logical comparisons between users.

For example:

@bot.event
async def on_message(message):
    if message.author != bot.user:
        await bot.send_message(message.channel, message.content)

Should function as desired


I know this question is from years ago but incase anybody else is googling this question like me, the message object that is passed to on_message has an author object inside of it, which has an attribute named "bot" which is true or false (true if it is a bot). So you can configure your function to safely ignore any messages by other bots by including this if statement at the beginning:

def on_message(self, message):
    if (message.author.bot):
        return #if this is true: then it is by a bot.