不和谐.py |如何检查正在发送的消息是直接发送到机器人 (DM) 还是在聊天中? [英] discord.py | How do I check if the message being sent is being sent directly to the bot (DM) or in a chat?
本文介绍了不和谐.py |如何检查正在发送的消息是直接发送到机器人 (DM) 还是在聊天中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查正在发送的消息 (on_message()) 是在发送给机器人的 DM 中,还是只是在任何其他地方发送,例如公会中的聊天.任何帮助将不胜感激.
I want to check to see if the message being sent (on_message()) is in a DM sent to the bot or just sent in any other place like a chat in a guild. Any help would be greatly appreciated.
@client.event
async def on_message(message):
if message type is dm:
#do stuff
elif message type is not dm:
#do something else```
推荐答案
你可以查看message.guild
.
@client.event
async def on_message(message):
if message.guild: # message is not DM
# do stuff
else: # message is DM
# do something else```
这篇关于不和谐.py |如何检查正在发送的消息是直接发送到机器人 (DM) 还是在聊天中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文