-1

I want to have a discord bot for my server that logs deleted messages in a specific channel. I have tried but I'm new to coding this is what I came up with and it doesn't work. The code is shown below:

async def on_message_delete(message):
    embed=discord.Embed(title="{} deleted a message".format(member.name.message), description="", color="teal")
    embed.add_field(name= message.content ,value="Deleted message", inline=True)
    channel=bot.get_channel(channel_id)
    await channel.send(embed=embed) 

Can anyone tell me what's wrong and the correct code please, it would be greatly appreciated and how to do logging for edited messages too

Iris XE
  • 1
  • 1
  • 5
    Well, what does not work? Be more specific please and maybe add a traceback if possible. – Dominik May 28 '21 at 19:26
  • 1
    Welcome to Stack Overflow! Please take a look at what's expected of a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). Not only do we not know what incorrect result you're currently getting, we can't test your code without writing the rest of it ourselves. – CrazyChucky May 28 '21 at 20:01
  • It says "NameError: name 'member' is not defined" @Dominik – Iris XE May 29 '21 at 20:59
  • Well, look at your code. You're trying to access `member.name.message`, but you haven't defined `member`. (Note that this still isn't a reproducible example and you haven't shown the full stack trace, so there may be other issues, but we have no way of knowing.) – CrazyChucky May 29 '21 at 21:18
  • How do i define "member" @CrazyChucky – Iris XE May 29 '21 at 21:20
  • For the purposes of this site, you should start by reading [How to Create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example), if you haven't already. Then edit your question so that you provide one. We don't necessarily need your entire *actual* code, but we do need a self-contained, runnable "test case", if you will, that generates the same problem you're having. And a full stack trace (the "in line __" stuff), not just the error message. – CrazyChucky May 29 '21 at 21:29
  • (Note: one exception to the usual rule that the provided code should be complete, such that we can copy and paste it and run it as-is, is that you *should not* include your Discord bot's unique token.) Here's a decent [example](https://stackoverflow.com/questions/67453633/how-to-snipe-messages-from-a-specific-channel-discord-py) of what a "complete" (testable) Discord bot MRE looks like. (There's no stack trace because they weren't getting a exception, just incorrect behavior.) – CrazyChucky May 29 '21 at 21:29

1 Answers1

0

Take a look to this code:

@bot.event
async def on_message_delete(message):
    embed = discord.Embed(
        title="{}'s message deleted.".format(message.author.name), #message.author is sender of the message
        description=message.content,
        color="teal"
    )
    channel=bot.get_channel(log_channel_id)
    await channel.send(embed=embed) 
Ali Hakan Kurt
  • 1,039
  • 5
  • 13