导入discord.py模块的问题

时间:2020-10-04 02:06:39

标签: python discord discord.py

StackOverflow。 我一直在与不和谐的机器人有问题,这是脚本:

    def send():
        url = "https://discordapp.com/api/webhooks/762125650546131005/lgYkjh-ILrag2sb3nzqUZfF1sg2mN2a0QeABaUq9dwl7qBTNL4EqWV00K62xWZ8_sNQ5"
        data = {}
        data["content"] = ""
        data["username"] = "Suggestions"

        data["embeds"] = []
        embed = {}

        embed["description"] = "**Author** » <@" + str(message.author.id) + ">\n **Suggestion** » " + str(args)
        embed["title"] = "**New Suggestion!**"
        data["embeds"].append(embed)

        result = requests.post(url, data=json.dumps(data), headers={"Content-Type": "application/json"})

    send()

    await message.author.send("Thank you for your suggestion! We will look into it as soon as possible and will message you if it will be used.")

当我执行“; suggestion fix bug”时,它只是发送到webhook“ fix”,这只是第一个单词,我正在努力解决此问题。请有人帮忙吗?

1 个答案:

答案 0 :(得分:0)

不要将请求与discord.py一起使用,它会同步并会阻止您的漫游器,将discord.Webhookaiohttp配合使用来发送discord.Embed

示例:

from aiohttp import ClientSession

async with ClientSession() as session:
    wh = discord.Webhook.from_url("<webhook url>", adapter=discord.AsyncWebhookAdapter(session))

    e = discord.Embed()
    e.title = "Hello I am an Embed"
    ...

    await wh.send(embed=e)