1. <tfoot id='OOmuU'></tfoot>
        <bdo id='OOmuU'></bdo><ul id='OOmuU'></ul>

        <legend id='OOmuU'><style id='OOmuU'><dir id='OOmuU'><q id='OOmuU'></q></dir></style></legend>
      1. <small id='OOmuU'></small><noframes id='OOmuU'>

        <i id='OOmuU'><tr id='OOmuU'><dt id='OOmuU'><q id='OOmuU'><span id='OOmuU'><b id='OOmuU'><form id='OOmuU'><ins id='OOmuU'></ins><ul id='OOmuU'></ul><sub id='OOmuU'></sub></form><legend id='OOmuU'></legend><bdo id='OOmuU'><pre id='OOmuU'><center id='OOmuU'></center></pre></bdo></b><th id='OOmuU'></th></span></q></dt></tr></i><div id='OOmuU'><tfoot id='OOmuU'></tfoot><dl id='OOmuU'><fieldset id='OOmuU'></fieldset></dl></div>

        当我的机器人发送时,Discord 没有嵌入链接

        时间:2023-10-10
        <legend id='siMoT'><style id='siMoT'><dir id='siMoT'><q id='siMoT'></q></dir></style></legend>
        <i id='siMoT'><tr id='siMoT'><dt id='siMoT'><q id='siMoT'><span id='siMoT'><b id='siMoT'><form id='siMoT'><ins id='siMoT'></ins><ul id='siMoT'></ul><sub id='siMoT'></sub></form><legend id='siMoT'></legend><bdo id='siMoT'><pre id='siMoT'><center id='siMoT'></center></pre></bdo></b><th id='siMoT'></th></span></q></dt></tr></i><div id='siMoT'><tfoot id='siMoT'></tfoot><dl id='siMoT'><fieldset id='siMoT'></fieldset></dl></div>

        <small id='siMoT'></small><noframes id='siMoT'>

        <tfoot id='siMoT'></tfoot>
            <tbody id='siMoT'></tbody>

                  <bdo id='siMoT'></bdo><ul id='siMoT'></ul>
                  本文介绍了当我的机器人发送时,Discord 没有嵌入链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的代码运行良好,机器人发送了链接,但 Discord 无法识别它,也没有嵌入它.当我自己复制并粘贴它时,它会将其识别为链接并嵌入图像.这是我的代码:

                  My code works fine and the bot sends the link, but Discord does not recognize it as one and does not embed it. When I copy and paste it myself, it then recognizes it as a link and embed the image. Here is my code:

                  import requests
                  from bs4 import BeautifulSoup
                  
                  
                  if message.content.startswith(".dog"):
                  
                      response = requests.get("https://dog.ceo/api/breeds/image/random")
                      soupRaw = BeautifulSoup(response.text, 'lxml')
                      soupBackend = str(soupRaw).split("message")
                      soup2 = soupBackend[1]
                      soup3 = soup2[3:]
                      soup = soup3[:-20]
                  
                      await bot.send_message(message.channel, soup)
                  

                  这里是一个例子:https://imgur.com/m9GM2wQ

                  有谁知道如何让它在我的机器人发送链接时嵌入链接?感谢您的帮助!

                  Does anyone know how to make it embed the link when it is sent by my bot? Thanks for the help!

                  我不是在尝试发送嵌入消息,而是在尝试发送将被 Discord 嵌入的链接,如我的示例所示.这不是重复的问题.

                  I am not trying to send an embedded message, I am trying to send a link that will BE embedded by Discord, as shown in my example. This is not a duplicate question.

                  推荐答案

                  很晚的答案,但如果有人在稍后查看此答案;我认为问题在于您的变量 soup 包含每个正斜杠的转义字符(反斜杠),例如https:\/\/images.dog.ceo\/breeds\/maltese\/n02085936_4480.jpg.

                  Very late answer, but if anyone is viewing this answer for later; I believe the problem is that your variable soup contains escape characters (backward slashes) for every forward slash, e.g. https:\/\/images.dog.ceo\/breeds\/maltese\/n02085936_4480.jpg.

                  将此作为消息发送(即使作为普通用户)会显示链接的外观,但不会自动为其创建嵌入.您可以使用函数 soup.replace("\", "") 替换反斜杠.

                  Sending this as a message (even as a regular user) shows the link as it should look, but does not automatically create an embed for it. You can replace the backslashes with the function soup.replace("\", "").

                  然而,我会推荐一种完全不同的方法,因为 response 对象有一个 .content 属性,它是 json 格式,可以很容易地被解析,并用作 pythondict,使用内置的 import json 库(它会自动为您留下转义码,您不必担心 response.text 的字符串长度).

                  I would however recommend a completely different approach as the response object has a .content attribute which is in json format and can easily be parsed, and used as a python dict, using the builtin import json library (It will automatically leave the escape codes for you and you don't have to worry about string length for response.text).

                  soup = json.loads(response.content).get("message") 应该可以解决问题.

                  这篇关于当我的机器人发送时,Discord 没有嵌入链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Discord bot 侦听特定频道上的命令 下一篇:Discord.py 如何发出静音命令?

                  相关文章

                  最新文章

                      <bdo id='wypnP'></bdo><ul id='wypnP'></ul>

                    <small id='wypnP'></small><noframes id='wypnP'>

                    <i id='wypnP'><tr id='wypnP'><dt id='wypnP'><q id='wypnP'><span id='wypnP'><b id='wypnP'><form id='wypnP'><ins id='wypnP'></ins><ul id='wypnP'></ul><sub id='wypnP'></sub></form><legend id='wypnP'></legend><bdo id='wypnP'><pre id='wypnP'><center id='wypnP'></center></pre></bdo></b><th id='wypnP'></th></span></q></dt></tr></i><div id='wypnP'><tfoot id='wypnP'></tfoot><dl id='wypnP'><fieldset id='wypnP'></fieldset></dl></div>
                  1. <legend id='wypnP'><style id='wypnP'><dir id='wypnP'><q id='wypnP'></q></dir></style></legend>
                      <tfoot id='wypnP'></tfoot>