我正在尝试在我的discord服务器中实现一个报告系统,因此当主持人不在线时,用户仍然可以向bot发送报告,bot将通知整个主持人频道
当我作为单个用户进行测试时,下面的代码工作正常;然而,我预测这不会那么容易。当用户执行以下操作时!report命令,另一个不同的用户向bot发送消息,bot会将其视为一个“会话”
请参见下面的屏幕截图
我希望机器人在自己的“会话”中处理所有用户。如果有人能为我指出正确的方向,我将不胜感激
为了进一步澄清,第一张图片是用户A,第二张图片是用户B,最后一张图片是最终报告。如您所见,用户A执行该命令,但如果用户B也对BOT进行DMs,则它会将该命令视为单个会话
@client.event
async def on_message(message):
if message.author == client.user:
return
if isinstance(message.channel, discord.DMChannel):
if message.content.startswith("!report"):
await message.channel.send("Who are we reporting?")
await message.channel.send("Follow this format: \n"
"User: <enter user ID> (to get a user's id please right click their name and Copy ID) \n"
"Reason: <enter reason> (ex include but not limited too: bullying, harassment, "
"offensive post ")
msg = await client.wait_for('message')
await message.channel.send("report received, an admin should be in contact with you soon")
channel = client.get_channel(REPORT_CHANNEL)
print(msg)
await channel.send("report received from user: {}#{}, unique User ID {} ".format(msg.channel.recipient.name, msg.channel.recipient.discriminator, msg.channel.recipient.id))
await channel.send(msg.content)
这是因为您采用了on_消息事件方法。处理这样的会话的最佳方法是使用命令
相关问题 更多 >
编程相关推荐