Reputation: 96
So, I want to log the edited message by member if they change it This is my code in the cogs so far:
@commands.Cog.listener()
async def on_message_edit(self,message,before,after):
guild = message.guild
channel = discord.utils.get(guild.channels, name="📝║logs")
embed = discord.Embed(timestamp=message.created_at, colour=red)
embed.set_author(name=f'{message.author.name}#{message.author.discriminator}', icon_url=message.author.avatar_url)
embed.set_footer(text=f"Author ID:{message.author.id} • Message ID: {message.id}")
embed.add_field(name="Member", value=f"<@{message.author.id}>", inline=True)
embed.add_field(name="Channel", value=f"<#{message.channel.id}>", inline=True)
embed.add_field(name="Message content before edited", value=message.before.content, inline=False)
embed.add_field(name="Message content after edited", value=message.after.content, inline=False)
await channel.send(embed=embed)
When I test it, I get this error:
Ignoring exception in on_message_edit
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
TypeError: on_message_edit() missing 1 required positional argument: 'after'
I don't get it. What have I done wrong?
Upvotes: 0
Views: 366
Reputation: 1413
That's because there is no message
argument in on_message_edit
event. Just do this:
async def on_message_edit(self,before,after):
The before
is discord.Message
object before edit and the after
is discord.Message
object after edit.
Upvotes: 1