如何在Discord中发送嵌入直接消息?

时间:2018-12-11 12:47:51

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

我正在从服务器捕获嵌入内容,我想将嵌入内容转发为直接消息。

所以我被这样嵌入:

@client.event                                              
async def on_message(message):
    embed = message.embeds[0]

现在,我修复了嵌入内容,以便将其发送给DM。因为它们的格式不正确。

我尝试使用Webhook将带有request.post的请求嵌入到“嵌入”的频道,并且有效。

当我尝试将“嵌入”发送到DM时不起作用。

webhook_url = 'https://discordapp.com/api/users/{}/{}'.format(user_id, token_bot)

def sendToDiscord(webhook_url, embed):
    headers = {
        'Content-Type': 'application/json',
    }
    response = requests.post(webhook_url, data= embed, headers=headers)
    return response

所以真正的问题是如何通过请求POST嵌入发送?

1 个答案:

答案 0 :(得分:0)

您可以使用此方法将嵌入内容发送到用户的直接消息

@bot.event                                              
async def on_message(message):
   emb=discord.Embed(title='Hello',description='Test message')
   emb.add_field(name='Name of field',value='The value for the field')
   await bot.send_message(,embed=emb)

另一种方法是使用whisper函数

@bot.event                                              
async def on_message(message):
    emb=discord.Embed(title='Hello',description='Test message')
    emb.add_field(name='Name of field',value='The value for the field')
    await bot.whisper(embed=emb)
相关问题