pythondiscordbots

Creating a command - Discord bot in Python


I am trying to create a simple command called infos_bot() for a Discord bot. The on_ready() stuff is working well but I can't figure out why is my new command not taken into account - i.e. nothing happens when I type the command within the server/channel.

Here is my code:

import discord
import nest_asyncio

bot_token = "duck" # My token
channel_id = 42 # My channel id

bot = discord.ext.commands.Bot(command_prefix="/",
                   intents = discord.Intents.default())

@bot.event
async def on_ready():
    print('Le haircut checker est connecté !')
    channel = bot.get_channel(channel_id)
    await channel.send('Le haircut checker est connecté !')
    
@bot.command(pass_context=True)
async def infos_bot(ctx):
    await ctx.send("""Blablabla""")
    
    
nest_asyncio.apply() # Don't know why but it debugs the code
bot.run(bot_token)

Solution

  • Finally, adding this simple chunck works fine after having created the intents variable:

    intents.message_content = True