问题描述
我一直在使用
import os
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "!")
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.idle,
activity=discord.Game(''))
print('Successfully logged in as {0.user}'.format(client))
@client.command()
async def hello(ctx):
await ctx.send("Hello! It's great to see you!")
client.run(os.getenv('TOKEN'))
命令代码.我希望它会回应你好!很高兴见到你!"当我说!你好(!=前缀).但它什么也没返回.甚至没有错误.有谁知道为什么?另外,请不要显示 discord bot 不响应命令 或 Discord command bot 没有响应 (python) 因为我都尝试了,但都没有成功.
code for commands. I expected to have it respond "Hello! It's great to see you!" when I said !hello (! = prefix). But it returned nothing. Not even an error. Does anyone know why? Also, please don't show discord bot not responding to commands or Discord command bot doesn't responde (python) because I tried both, and neither worked.
推荐答案
因为名声不好,不能在这里聊天,所以在这里回答.您应该发布完整的代码以使工作更轻松.
I cant chat here because of lack of reputation so I answer it here instead. you should post the full code to make the job easier.
.
原因1:
您没有添加前缀.您需要一个前缀才能使用该命令
You didn't add a prefix. You need a prefix to use the command
查看您的客户端
.你已经告诉前缀了吗?喜欢:
look onto your client
. Did you tell the prefix already? like:
client = commands.Bot(command_prefix = "-")
如果是这样,添加它,它应该可以工作!
if so, add this and it should work!
.
原因2:
您没有从 discord.ext 导入命令中导入
You didn't import from discord.ext import commands
如果你想使用命令,这很重要,导入它应该可以工作!
this is important if you want to use commands, import that and it should work!
.
原因 3:
你混淆了 client
和 bot
这可能不会发生,但它会发生,你可能会在装饰器上混淆 client
或 bot
,即 @client.command
this might not happen but here it goes, You might mix up client
or bot
on the decorator, which is @client.command
如果你使用客户端(如 client = commands.Bot(command_prefix = "-")
),请在装饰器上使用 @client.command
,而如果你使用 Bot (bot = commmands.Bot(command_prefix = "-")
) 那么你应该在装饰器上使用 @bot.command
.
if you use client (like client = commands.Bot(command_prefix = "-")
), use @client.command
on the decorator, while if you use Bot (bot = commmands.Bot(command_prefix = "-")
) then you should use @bot.command
on the decorator.
希望这些会有所帮助:D
Hope these will help :D
这篇关于Discord 机器人没有响应命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!