Discord Bot 无法识别命令名称
Discord Bot not recognizing command names
这是我为了启动 discord 机器人而写的,但是每当我尝试使用命令 ?hi 时,我都会收到错误消息
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "hi" is not found"
我尝试了一些东西,但我是新手,没有任何效果。
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")
为了创建 discord 机器人,您需要 discord 提供的身份验证令牌。我看到你的机器人正在使用 discord.py。他们对 how to create a bot account
有解释
至于你的bot的代码,你首先需要创建一个bot Client然后运行它,就像这里
import discord
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
client.run('your token here')
运行启用机器人
时不要忘记添加您的令牌
在所有这些都准备就绪之后,您就可以使用 discord.ext 模块像您一样创建命令了。 (您的代码有效,只是缺少上面显示的整个不和谐机器人部分)
ext代表扩展,如果你连主模块(discord)都没有,那它就什么都做不了
Take not that discord and discord.ext are 2 different modules, so you need to import both
这是我为了启动 discord 机器人而写的,但是每当我尝试使用命令 ?hi 时,我都会收到错误消息
Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "hi" is not found"
我尝试了一些东西,但我是新手,没有任何效果。
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")
为了创建 discord 机器人,您需要 discord 提供的身份验证令牌。我看到你的机器人正在使用 discord.py。他们对 how to create a bot account
有解释至于你的bot的代码,你首先需要创建一个bot Client然后运行它,就像这里
import discord
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
client.run('your token here')
运行启用机器人
时不要忘记添加您的令牌在所有这些都准备就绪之后,您就可以使用 discord.ext 模块像您一样创建命令了。 (您的代码有效,只是缺少上面显示的整个不和谐机器人部分)
ext代表扩展,如果你连主模块(discord)都没有,那它就什么都做不了
Take not that discord and discord.ext are 2 different modules, so you need to import both