問題描述
我一直在使用
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 機器人沒有響應命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!