检查消息是否由用户以DM(discord.py)发送,然后将其消息从直接消息发送到某个频道?

时间:2020-08-28 20:04:47

标签: python python-3.x discord.py

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编写它?

2 个答案:

答案 0 :(得分:1)

这应该是一个例子

@bot.event
async def on_message(message)
guild = message.guild
if not guild:
    print(" DM: {0.author.name} : {0.content}".format(message))

答案 1 :(得分:0)

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)