我如何阅读bot DM并使用discord.py将其转发到频道?

问题描述 投票:0回答:1

我正在尝试创建一个能够接收DM并将其与发送DM的人的用户名和用户ID一起转发到服务器中特定通道的消息的机器人。这是我尝试过的。它似乎没有用,尽管我认为我的其余代码有可能会影响它。

@client.event
async def on_message(message):
    channel = client.get_channel(714242239215304745)
    if message.guild is None and message.author != client.user:
        embed = discord.Embed(
            title = 'Support requested!',
            description = '{}' .format(message.content),
            color = discord.Color.from_rgb(r=159, g=255, b=255)
            )
        embed.set_footer(text='Requested by {} | ID-{}' .format(message.author, message.author.id))
        await channel.send(embed=embed)
        print("Support requested by {} | ID-{}!" .format(message.author, message.author.id))
        print("Content: '{}'." .format(message.content))
    await client.process_commands(message)

我的其余代码可以在here中找到。

python discord discord.py
1个回答
0
投票

尝试使用message.channel == message.author.dm_channel,并且f字符串与.format()相对。

@client.event
async def on_message(message):
    channel = client.get_channel(714242239215304745) # are you sure this channel exists?
    if message.channel == message.author.dm_channel: # do not use guild == None, as group dms might satisfy this, and you can't message yourself, no need to check client user
        embed = discord.Embed(
            title = 'Support requested!',
            description = f'{message.content}',
            color = 0x9fffff
            )
        embed.set_footer(text=f'Requested by {message.author.display_name} | ID-{message.author.id}')
        await channel.send(embed=embed)
        print("Support requested by {} | ID-{}!" .format(message.author, message.author.id))
        print("Content: '{}'." .format(message.content))
    await client.process_commands(message)
© www.soinside.com 2019 - 2024. All rights reserved.