【发布时间】:2021-10-10 12:31:40
【问题描述】:
我正在尝试使用不和谐机器人开发游戏。我在处理 onmessage 例程时遇到了麻烦。我只需要它来“收听”一个特定的频道,而不是所有的服务器。现在我做了以下事情:
@client.event
async def on_message(message):
global rojo
global IDS
canal = IDS['C_Juego']
if message.author == client.user or str(message.channel) != IDS['C_Juego']:
return
else:
if(rojo == 1):
autor = message.author
await message.add_reaction("????")
await message.channel.send("Player: " + str(autor) + " removed!")
role = get(message.guild.roles, name="Jugador")
await message.author.remove_roles(role)
elif(str(message.channel) == IDS['C_Juego']):
await message.add_reaction("????")
print("verde")
发生了什么事?当我启用此功能时.. 除了发送的每条消息都会调用此功能之外,我的其余命令停止生效(在服务器的任何通道中)....
我解释一下背景:这是一个游戏,玩家在听一首歌时必须在一个主题下放置不同的单词,当音乐停止时,如果有人写,他们就会被淘汰。 p>
命令定义: 我有很多命令定义......在我添加这个有问题的功能之前它工作正常......我添加其中两个作为示例:
@client.command()
@commands.has_role("Owner")
async def clear(ctx):
await ctx.channel.purge()
@client.command()
@commands.has_role("Owner")
async def swipe(ctx, role: discord.Role):
print(role.members)
for member in role.members:
await member.remove_roles(role)
await ctx.send(f"Successfully removed all members from {role.mention}.")
【问题讨论】:
-
你是如何定义其他命令的,使用 on_message 或
@client.command()装饰器? -
是的!很多,我会将这些信息添加到问题中
标签: python discord discord.py