[英]Check if a message was sent by a user in a DM (discord.py) then send their message from a direct message into a certain channel?
msg_dump_channel = 1234
@bot.event
async def on_message(message: discord.Message):
channel = bot.get_channel(msg_dump_channel)
if str(message.author) == "user":
await channel.send(message.content)
await bot.process_commands(message)
这是我的代码,我知道DM没有公会,那么你会如何为DM编写它?
discord.Message
对象具有可用于检查的channel
属性:
@bot.event
async def on_messsage(message)
if isinstance(message.channel, discord.DMChannel) and str(message.author) == 'user':
channel = bot.get_channel(channel_id)
await channel.send(message.content)
else:
pass
bot.process_commands(message)
这应该是一个例子
@bot.event
async def on_message(message)
guild = message.guild
if not guild:
print(" DM: {0.author.name} : {0.content}".format(message))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.