不和谐机器人的命令不起作用(Python)

Posted

技术标签:

【中文标题】不和谐机器人的命令不起作用(Python)【英文标题】:Commands for discord bot not working (Python) 【发布时间】:2021-10-05 22:39:00 【问题描述】:

我不确定为什么这些命令不起作用。每当我在我的不和谐服务器中输入 !hello 时,机器人都没有响应。

import discord
from discord.ext import commands
import os

my_secret = os.environ['Token']
client = commands.Bot(command_prefix='!')

@client.command(pass_context=True)
async def hello(ctx):
  await ctx.send("Hello")


client.run(my_secret)

【问题讨论】:

【参考方案1】:

这应该工作 我刚刚测试了它,它工作得很好 你安装了 Discord 吗?你的 Token 写对了吗?

您还应该将此代码放入您的代码中,以便查看 Bot 何时准备就绪

@client.event
async def on_ready():
print(" ")
print("Bot started! | Informations:")
print(f"- Name: client.user.name") 
print(f"- Bot-ID: client.user.id") 
print(f"- Server using client.user.name:",
      len(client.guilds))

【讨论】:

是的,我有我的令牌和所有启动我的机器人和东西的东西。我正在尝试向我的机器人添加命令,当我输入触发词时,我的机器人在聊天中没有发送任何内容。 您的 Bot 是否有权查看聊天中的消息?

以上是关于不和谐机器人的命令不起作用(Python)的主要内容,如果未能解决你的问题,请参考以下文章