【问题标题】:"Command not found" discord bot“找不到命令”不和谐机器人
【发布时间】:2022-01-15 14:24:18
【问题描述】:

所以我正在制作一个包含多个命令的不和谐机器人,但似乎只有最上面的一个可以工作。

import discord
import os
import time
import discord.ext
from discord.utils import get
from discord.ext import commands, tasks
from discord.ext.commands import has_permissions,  CheckFailure, check

client = discord.Client()

client = commands.Bot(command_prefix = '$')

count = 0

@client.event
async def on_ready():
    print("Ready")

@client.command()
async def clear(ctx, amount=100):
  await ctx.channel.purge(limit=amount)
  return

async def hello(ctx):
  await ctx.send("Hi")
           

async def help(ctx):
    await ctx.send("Hi")



client.run(("token")) 
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "hello" is not found

如果您能告诉我哪里出了问题,我将不胜感激。

【问题讨论】:

  • 您从未发出过名为hello 的命令。你做了这个函数,是的,但你没有把它附加到一个不和谐的命令上
  • @client.command() 在最后两种情况下丢失。投票结束为拼写错误
  • 那么我如何使它成为一个命令@12944qwerty
  • 您在创建clear 时发出了命令。复制您用于其他命令的装饰器。
  • @client.command 是装饰器吗?

标签: python discord discord.py


【解决方案1】:

如果没有装饰器,该函数没有注册为命令,因此无法执行,每次都要放

@client.command()
async def clear(ctx, amount=100):
  await ctx.channel.purge(limit=amount)
  return

@client.command() # The decorator must be put here
async def hello(ctx):
  await ctx.send("Hi")
           
@client.command() # ... and here too, everytime a function is a command
async def help(ctx):
    await ctx.send("Hi")

【讨论】:

    猜你喜欢
    • 2018-07-21
    • 2018-11-10
    • 2021-10-21
    • 2021-06-17
    • 2017-05-31
    • 2019-09-04
    • 2021-10-05
    • 2020-11-18
    • 2020-07-09
    相关资源
    最近更新 更多