'How to send a embed message discord.py
I am trying to send this embed message to a channel, I will keep trying and changing things around and it does not want to work, the problem is that it does not recognize the ".send", because it can not be called with channel. I would really appreciate it if someone would explain this to me. MY ERROR:
Traceback (most recent call last):
File "C:\Users\jaspe\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\jaspe\OneDrive\Desktop\DISCORD_BOT\zdiscord bot.py", line 19, in on_message_edit
await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'
My code:
@bot.event
async def on_message_edit(message_before, message_after):
embed = discord.Embed(title="{} edited a message".format(message_before.author.name),description="", color=0xFF0000)
embed.add_field(name=message_before.content, value="This is the message before any edit",inline=True)
embed.add_field(name=message_after.content, value="This is the message after the edit",inline=True)
channel = bot.get_channel("My channel id")
await channel.send(embed=embed)
Solution 1:[1]
Change this part:
channel = bot.get_channel("My channel id")
To:
channel = discord.utils.get(message_before.guild.text_channels, id=put_id_here)
The way you are getting the channel is probably returning None, which of course has no method named send
Solution 2:[2]
The channel ID you are trying to provide must be an INTEGER, but you provided a STRING.
@bot.event
async def on_message_edit(message_before, message_after):
embed = discord.Embed(title="{} edited a message".format(message_before.author.name),description="", color=0xFF0000)
embed.add_field(name=message_before.content, value="This is the message before any edit",inline=True)
embed.add_field(name=message_after.content, value="This is the message after the edit",inline=True)
channel = bot.get_channel(1234567890)
await channel.send(embed=embed)```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sandy |
| Solution 2 | Ian Cheung |
