【发布时间】:2021-11-10 15:01:05
【问题描述】:
这是我为了启动我的不和谐机器人而写的,但是每当我尝试使用命令 ?hi 时,我都会收到错误消息
忽略命令 None 中的异常: discord.ext.commands.errors.CommandNotFound:找不到命令“hi””
我尝试了几件事,但我是新手,没有任何效果。
import discord
from discord.ext import commands, tasks
import os
import random
client = commands.Bot(command_prefix = '?')
@client.command
async def hi(ctx):
await ctx.send("Hello World")
下面的答案有助于解决这个问题,这是我的新代码,因为机器人现在不给出错误消息,但不响应命令
import discord
from discord.ext import commands
import os
import random
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
client.run('Token')
client = commands.Bot(command_prefix = '?')
@client.command
async def hi(ctx):
await ctx.send("Hello World")
【问题讨论】:
-
以前从未创建过机器人,但您在函数之前不需要
@client.command(name='hi')之类的东西吗? -
好吧@depperm 我试过了,现在它正在识别命令,我收到一条我理解更少的新错误消息
-
新的错误信息是什么?
-
@depperm 我确实一直在弄乱它,也许你可以帮忙错误
@client.command async def hi(ctx): @client.command(name=hi(ctx)) await ctx.send("Hello World") -
请编辑您的问题或提出新问题。缩进对python很重要。你看起来不像我上面评论的那样。
标签: python discord command bots