[Python] Cant run discord commands made in python

Discussão em 'Python' iniciado por Stack, Março 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am writing a discord bot for the first time. I managed to debug a few things from the tutorial, like the fact that there is a new argument: intents, but when it came to creating commands I could not find any solution.

    Basically my problem is that the commands are not working. Eventually I decided to give up and at least hope something simple would work (and not complicated commands) so I tried this:

    import discord
    from discord.ext import commands
    TOKEN = '(my bot ID that is already added in my code)'

    # Define the bot prefix
    bot = commands.Bot(command_prefix='!',intents=discord.Intents.default())

    @bot.event
    async def on_ready():
    print(f'The bot is ready have logged in as {bot.user}')

    @bot.command()
    async def test(ctx):
    await ctx.send('Test')

    # Run the bot
    bot.run(TOKEN)


    What I expected to happen, is that when I did '!test' it would send "Test". But the bot did not respond with anything Then I tried doing a lot of things. Changing permissions to moderator, running it with F5 instead of python bot.py, running it with python bot.py instead of F5 (I usually do F5 but I still don't know if either of them work), etc.

    So now I am stuck with a broken bot and the bot commands won't do what they are supposed to. A couple of websites I checked were for example things to change the bot to client, or questions about importing the right modules, adding all intents (that didn't even work, it just said there was an error in the module when I tried discord.Intents.all()), etc. I also tried intents = discord.Intents.default() intents.message_content = True, as somebody suggested that, and that bugged the whole thing, causing a lot of errors mostly about the installed module.

    How to resolve the issue?

    Continue reading...

Compartilhe esta Página