discord.py: on_message(message) dont works since a few days

Viewed 99

Since a few days two of my bots dont react on_message(message). In console there show no error.

for example a simple badword script. since last week it worked fine. but now ... no output.

@bot.event
async def on_message(message):
    bad_words = ['badword1','badword2','badword3','badword4','badword5','badword6']
    if message.author == bot.user:
        return
    for word in bad_words:
        if 0 < message.content.count(word) < 2:
            await message.channel.send("{}, bitte achte auf Deine Wortwahl.".format(message.author.mention))
            await message.delete()
            break
    else:
        await bot.process_commands(message)

I don't know what is wrong. i hope someone can help me please.

1 Answers

There're some updates about Intents in the discord.py 1.5.x. Intents are like permissions, you have to define it to use some events like on_message and getting members, channels etc. You need to define it before defining bot = discord.Bot(prefix='') to get guilds, channels etc.

import discord
intents = discord.Intents().all()
bot = discord.Bot(prefix='', intents=intents)

For more information about intents, you can look at the API References.

Related