消息发送命令有问题



我正在尝试使用此代码执行重复命令:

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')

但是当发送带有命令的消息时,bot既不响应想要的消息,也不响应暗示某些事情不正确的错误。我对编程也很陌生,所以它可能是一些我不知道的愚蠢的东西。如有任何帮助,不胜感激。

如果您仔细检查您的代码,您将看到您将命令分配给client对象,但运行的是bot对象。你需要像另一个评论者建议的那样做client.run("<TOKEN>")

你也不需要bot = discord.Client()discord.Client是一个能力较弱的父类。我建议您将client重命名为bot

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')

注意现在没有import discorddiscord.Client

参见:Bot和Client之间的区别是什么?

最新更新