Discord 机器人没有响应命令

Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
本文介绍了Discord 机器人没有响应命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我一直在使用

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:

你混淆了 clientbot

这可能不会发生,但它会发生,你可能会在装饰器上混淆 clientbot,即 @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 机器人没有响应命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I make a list of all members in a discord server using discord.py?(如何使用 discord.py 列出不和谐服务器中的所有成员?)
how to change discord.py bot activity(如何更改 discord.py 机器人活动)
Issues with getting VoiceChannel.members and Guild.members to return a full list(让 VoiceChannel.members 和 Guild.members 返回完整列表的问题)
Add button components to a message (discord.py)(将按钮组件添加到消息(discord.py))
on_message() and @bot.command issue(on_message() 和@bot.command 问题)
How to edit a message in discord.py(如何在 discord.py 中编辑消息)