[英]Discord.py Issue
import discord
import os
import discord.ext
#^ basic imports for other features of discord.py and python ^
client = discord.Client()
@client.event
async def on_message(message):
if message.author.id == 526450002986401805: message.channel.send('https://cdn.discordapp.com/attachments/832402714603552838/978450412204085258/837F372D-4793-42F4-A24E-AFE399BB4B88.jpg')
client.run(os.getenv("TOKEN"))
每當我在鍵入消息后為不和諧機器人運行以下代碼以便機器人將鏈接發送到圖像時,我都會收到錯誤消息:
main.py:8: RuntimeWarning: coroutine 'Messageable.send' was never awaited
if message.author.id == 526450002986401805: message.channel.send('https://cdn.discordapp.com/attachments/832402714603552838/978450412204085258/837F372D-4793-42F4-A24E-AFE399BB4B88.jpg')
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
我對編碼很陌生,如果它是超級簡單的東西,很抱歉!
'Messageable.send' was never awaited
告訴你這里出了什么問題。
該庫是async
的,因此如果您想發送消息,在這里舉例說明,您必須await
它。
您的新代碼:
if message.author.id == 526450002986401805:
await message.channel.send('TheContentHere')
這是您正在制作的任何東西的更高級版本
@client.event
async def on_message(message):
embed = discord.Embed(title="Time Limit", color=0xff007f)
embed.set_image(url="https://cdn.discordapp.com/attachments/832402714603552838/978450412204085258/837F372D-4793-42F4-A24E-AFE399BB4B88.jpg")
if message.author.id == 526450002986401805:
await message.channel.send(embed=embed)
它給您“等待”錯誤的原因是因為該消息從未等待,因此無法發送。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.