【问题标题】:Having problem with message sending command消息发送命令有问题
【发布时间】:2021-04-29 17:50:47
【问题描述】:

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

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

但是当发送带有命令的消息时,机器人既不会响应所需的消息,也不会出现暗示某些事情不正确的错误。我对编程也很陌生,所以我不知道这可能是一些愚蠢的事情。任何帮助表示赞赏。

【问题讨论】:

  • 你真的在运行机器人吗?文件末尾有client.run("TOKEN")
  • 是的,它表明该机器人在不和谐上在线并说它已登录到该机器人
  • 它显示 a 机器人在线,但不是你想要的:P

标签: discord.py


【解决方案1】:

如果您仔细检查您的代码,您会发现您正在将命令分配给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

见:What are the differences between Bot and Client?

【讨论】:

  • 我更改了“客户端”和“机器人”的位置,但结果相同
  • 我没有说只是交换名字。根本问题是您声明了两个对象 A 和 B,将命令分配给 A,但随后运行 B。单独交换 A 和 B 并不能解决此问题。
  • 你是对的,该命令在分配代码以运行机器人和它的命令后工作
  • 很高兴听到! TL;DR 不要使用discord.Client
猜你喜欢
  • 1970-01-01
  • 2021-07-09
  • 2016-01-13
  • 2010-10-16
  • 2021-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多