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.

Zoronic
  • 5
  • 2

1 Answers1

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?

effprime
  • 578
  • 3
  • 10
  • I changed the places of 'client' and 'bot' but i'm experiencing the same results – Zoronic Jan 25 '21 at 22:21
  • 1
    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. – effprime Jan 25 '21 at 22:25
  • You are right, the command works after assigning the code to run both the bot and command it worked – Zoronic Jan 25 '21 at 22:29
  • Great to hear! TL;DR don't use `discord.Client` – effprime Jan 25 '21 at 22:31