The bot events doesn't working discord.py

Viewed 30

I am trying to make a simple on_message event for the bot but somehow the bot is ready and online, but no event is working...

Here is an example of my code:

import discord

token = "--My token--"

client = discord.Client()

@client.event
async def on_ready():
    print(f"Connected to APPLICATION {client.user}")

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith("$test"):
        await message.channel.send("test")
            
client.run(token)

1 Answers

U need to have intents enabled in discord.py v.2.0 for it to work. You can use discord.Intents.all() to enable all intents or you can also use discord.Intents.default() if u prefer to only enable default intents.

import discord

token = "--My token--"

intents = discord.Intents.all()

client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f"Connected to APPLICATION {client.user}")

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith("$test"):
        await message.channel.send("test")
            
client.run(token)
Related