【问题标题】:discord.py command is not found找不到 discord.py 命令
【发布时间】:2021-11-11 12:38:47
【问题描述】:

机器人一直给我这个错误:

忽略命令中的异常无:
discord.ext.commands.errors.CommandNotFound:找不到命令“rs”

import discord
from discord.ext import commands
from datetime import datetime
from discord import client

print("holaaaaaa")
token = "token"
client = commands.Bot(command_prefix=("."))

contatore1 = 0
redstar = "@everyone Vorrei fare una rs "
partecipanti = "\n Partecipanti: "

support = "0/4"

@client.event
async def on_ready():
    print(client.user, "ONLINE ","(ID ", client.user.id,")")

@commands.command()
async def rs(message):
    if message.channel.id == 605465213956915218:
        global redstar
        global contatore5
        global tag5
        global support5
        global partecipanti
        redstar = "@everyone Vorrei fare una " + message.channel.name
        tag5 = "\n" + message.author.mention
        contatore5 = 1
        if (contatore5 == 1):
            support5 = "1/4"
            await message.send(redstar + partecipanti + support5 + tag5)
    if (message.channel.id == 605465543134150657):
        global contatore6
        global tag6
        global support6
        redstar = "@everyone Vorrei fare una " + message.channel.name
        tag6 = "\n" + message.author.mention
        contatore6 = 1
        if (contatore6 == 1):
            support6 = "1/4"
            await message.send(redstar + partecipanti + support6 + tag6)

client.run(token)

另外,应该注意 on_ready 事件会运行。
感谢您提供任何帮助:)

【问题讨论】:

  • 我猜它必须是client.command(),因为它不在Cog 中。因此,命令以ctx 参数开头。 message 主要用于像 on_message 这样的事件。要在命令中使用message,只需说ctx.message
  • 它不必是@client.command,即使它在齿轮之外,但@client.command 确实使它更容易。如果您出于某种原因想要在不使用@client.command 的情况下发出命令,那么您可以在函数下方和client.run 之前的某处添加client.add_command(rs)
  • 如果你阅读源代码你可以看到@client.command actually uses client.add_command

标签: python discord discord.py bots


【解决方案1】:

您可以通过 2 种方法继续解决您的问题。

  • Dominik 建议的那个,您需要将@commands.command() 更改为@client.command()。所以喜欢改变

    @commands.command()
    async def rs(message):
    

    @client.command()
    async def rs(message):
    
  • 之后使用bot.add_command 手动添加命令。有了这个,你必须添加

    client.add_command(rs)
    

    位于命令定义下方和 client.run 上方。

我个人建议第一种方法,因为它更简洁。

【讨论】:

    猜你喜欢
    • 2021-11-14
    • 2017-04-16
    • 2021-06-06
    • 2019-03-24
    • 2021-04-16
    • 2021-02-19
    • 2021-03-13
    • 2021-03-16
    相关资源
    最近更新 更多