【问题标题】:How to send embed to direct message in Discord?如何在 Discord 中发送嵌入到直接消息?
【发布时间】:2019-05-12 11:13:38
【问题描述】:

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

所以我像这样嵌入:

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

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

我尝试使用带有 Webhook 的 requests.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 嵌入?

【问题讨论】:

  • 为什么不使用client.send_message 将嵌入发送到频道?
  • 因为它是另一种格式

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


【解决方案1】:

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

@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)

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 2021-09-15
    • 2018-11-24
    • 2020-06-12
    • 2023-01-12
    • 2021-12-28
    • 2021-09-30
    • 1970-01-01
    • 2021-05-15
    相关资源
    最近更新 更多