【发布时间】: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.commandactually usesclient.add_command
标签: python discord discord.py bots