python - 导入 discord.py 模块的问题
问题描述
堆栈溢出。我一直遇到不和谐机器人的问题,这是脚本:
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 bugs”时,它只会发送到 webhook “fix”,这只是第一个词,我正在努力解决这个问题。请问有人可以帮忙吗?
解决方案
不要将请求与 discord.py 一起使用,它是同步的并且会阻止您的机器人,使用带有aiohttp的discord.Webhook来发送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)
推荐阅读
- xamarin.forms - Xamarin 表单 - 将参数传递给 xaml 文件中指定的 bindingcontext 视图模型
- asp.net-web-api - 发布到 asp.net core web api 的数据导致参数为空
- r - 在 R 中查找区域年度最大值
- php - 错误包括(php.php):无法打开流:没有这样的文件或目录 Yii 版本 1.1.22 + S3
- cluster-analysis - ELKI:如何为 K-Means 指定 CSV 的特征列
- elasticsearch - 拆分文本包含
分成 3 个令牌 - woocommerce - 在 Woocommerce API 的重复 SKU 检查之前是否有一个钩子?
- notifications - 您可以在退出区域时对 ibeacon 通知应用时间限制吗?
- coldfusion - 冷箱模型关系
- amazon-ec2 - aws 实例 EC2。它会自动关闭。因为你可以自动打开它