【问题标题】:Discord Bot - Python不和谐机器人 - Python
【发布时间】:2021-10-30 08:14:16
【问题描述】:

我正在尝试创建一个不和谐的机器人并向其添加一些命令,但它似乎不起作用。 我添加了 print 语句来确定是否添加了命令,但它返回 None。在不和谐频道中调用“!hello”会引发 CommandNotFound。

from discord.ext import commands

client = commands.Bot(command_prefix="!")
TOKEN = [some token]


@client.command
async def hello(ctx, arg):
    await ctx.channel.send(arg)

print(client.get_command("hello"))

client.run(TOKEN)

【问题讨论】:

    标签: python discord discord.py bots


    【解决方案1】:

    那是因为@client.command 后面少了括号,只需像这样添加() 即可:

    @client.command()
    

    【讨论】:

      【解决方案2】:

      ctx.channel.send() 需要替换成 ctx.send() 正如loloToster 刚才所说,@client.command 需要 () 在它后面 所以最终的代码是:

      from discord.ext import commands
      
      client = commands.Bot(command_prefix="!")
      TOKEN = [some token]
      
      
      @client.command()
      async def hello(ctx, arg):
          await ctx.send(arg)
      
      print(client.get_command("hello"))
      
      client.run(TOKEN)
      

      【讨论】:

        猜你喜欢
        • 2021-05-27
        • 2021-07-15
        • 2021-03-29
        • 2021-07-11
        • 2021-03-25
        • 2018-08-13
        • 1970-01-01
        • 2021-02-28
        • 2021-07-13
        相关资源
        最近更新 更多