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

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

discord.py - Having problem with message sending command

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...