Programming Maniac
Programming Maniac

Reputation: 127

Discord.py bot not reading other bot's messages

When I run the python code below, it doesn't pick up messages from other bots:

@bot.event
async def on_message(message):
    print(message)

Is there any way to make so that my discord.py bot does pick up messages from other bots?

Upvotes: 2

Views: 2278

Answers (3)

Daniel O'Brien
Daniel O'Brien

Reputation: 365

Discord.py bots are set to ignore messages sent by other bots, see the code here - more specifically lines 972 and 973:

if message.author.bot:
    return

To work around this, you can subclass the bot, and override the process_commands method as shown below:

class UnfilteredBot(commands.Bot):
    """An overridden version of the Bot class that will listen to other bots."""

    async def process_commands(self, message):
        """Override process_commands to listen to bots."""
        ctx = await self.get_context(message)
        await self.invoke(ctx)

and run your code using this bot instead. Probably not the best to use in production, but is a good way to facilitate testing of your bot via another bot

Upvotes: 2

Ecks Dee
Ecks Dee

Reputation: 471

As the messages are from bots, could it be because the bots are using embeds? Because discord cannot print message from embeds(Maybe unless if you use message.embeds) Check if the messages the bots are sending are plain text instead of embeds

Upvotes: 1

Programming Maniac
Programming Maniac

Reputation: 127

I decided to just use the channel.history(limit=10).flatten() and channel.fetch_message(ID) functions and put them in a loop, which also works well for my application.

Upvotes: 1

Related Questions