我的机器人无法响应命令时遇到了问题。这是我的代码:
$ curl -k --user elastic:$ELASTIC_PWD https://localhost:9200/_cluster/allocation/explain?pretty
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "unable to find any unassigned shards to explain [ClusterAllocationExplainRequest[useAnyUnassignedShard=true,includeYesDecisions?=false]"
}
],
"type" : "illegal_argument_exception",
"reason" : "unable to find any unassigned shards to explain [ClusterAllocationExplainRequest[useAnyUnassignedShard=true,includeYesDecisions?=false]"
},
"status" : 400
}
在代码中,我还有其他针对该机器人的客户端事件,例如对消息做出反应和对消息进行回复。我上面的代码即使在我注释掉所有其他注释后也无法正常工作。在运行程序时,我在不和谐频道中输入了!test arg,但是只有在未注释掉它的情况下,我的机器人才会收到编程的反应。
答案 0 :(得分:1)
一次只能运行一个Bot / Client。我将使用Bot
,因为Bot
类是Client
类的子类,因此它可以完成父级可以做的所有事情。
from discord.ext import commands
import discord.utils
bot = commands.Bot(command_prefix='!')
@bot.event #server + member list
async def on_ready():
guild = discord.utils.get(bot.guilds, name=GUILD)
print(
f'{client.user} is connected to the following guild:\n'
f'{guild.name}(id: {guild.id})\n'
)
members = '\n - '.join([member.name for member in guild.members])
print(f'Guild Members:\n - {members}')
@bot.command()
async def test(ctx, arg):
await ctx.send(arg)
bot.run(TOKEN)