Skip to content
Advertisement

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"))

Whenever I run the following code for a discord bot after I type a message so that the bot sends the link to the image I get the error:

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

I am pretty new to coding, so sorry if it’s something super simple!

Advertisement

Answer

'Messageable.send' was never awaited tells you what went wrong here.

The library is async so if you want to send a message, to state an example here, you have to await it.

Your new code:

if message.author.id == 526450002986401805:
    await message.channel.send('TheContentHere')
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement