Discord.py 问题
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"))
每当我输入消息后 运行 discord 机器人的以下代码,以便机器人将 link 发送到图像时,我收到错误消息:
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)
它给你一个“等待”错误的原因是因为从未等待消息,所以它无法发送。
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"))
每当我输入消息后 运行 discord 机器人的以下代码,以便机器人将 link 发送到图像时,我收到错误消息:
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)
它给你一个“等待”错误的原因是因为从未等待消息,所以它无法发送。