0

I am trying to do a repeat command with this code:

import discord
from discord.ext import commands

bot = discord.Client()

client = commands.Bot(command_prefix='V!')


@client.command(name='repeat')
async def _repeat(ctx, arg):
    await ctx.send(arg)

bot.run('TOKEN')

but when sending a message with a command, the bot doesnt respond neither with the wanted message, nor an error that would imply something is not right. i am also very new to programming so it may be something dumb that i do not know. Any help is appreciated.

3
  • 1
    Are you actually running the bot? With client.run("TOKEN") at the end of the file? Commented Jan 25, 2021 at 21:57
  • yes, it shows that the bot is online on discord and says that it logged into the bot Commented Jan 25, 2021 at 22:00
  • 1
    It shows a bot as online, but not the one you want :P Commented Jan 25, 2021 at 22:17

1 Answer 1

1

If you examine your code carefully, you'll see that you are assigning the command to the client object, but running the bot object. You need to do client.run("<TOKEN>") as another commenter suggested.

You also don't need bot = discord.Client() at all. discord.Client is a parent class with less abilities. I encourage you to rename client to bot though.

from discord.ext import commands

bot = commands.Bot(command_prefix='V!')

@bot.command(name='repeat')
async def _repeat(ctx, arg):
    await ctx.send(arg)

bot.run('TOKEN')

Notice now there's no import discord or discord.Client anywhere.

See: What are the differences between Bot and Client?

Sign up to request clarification or add additional context in comments.

4 Comments

I changed the places of 'client' and 'bot' but i'm experiencing the same results
I didn't say just exchange the names. The underlying issue is you've declared two objects A & B, assigned a command to A, but then ran B. Exchanging A & B alone doesn't fix this issue.
You are right, the command works after assigning the code to run both the bot and command it worked
Great to hear! TL;DR don't use discord.Client

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.