Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

question from:https://stackoverflow.com/questions/65892988/having-problem-with-message-sending-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...