how do I get my bot to say who deleted the message?
Problem Description:
So I was following various guides, and I built this message create
event but was having a problem getting it to say who sent the message.
Here is my code
badword = ['test']
client.on('messageCreate', (message) => {
if (message.content == badword){
message.delete(message)
.then(msg => console.log(`Deleted message from ${msg.author.username.tag}`))
.catch(console.error);
}
})
And the console log
Deleted message from undefined
I was also wondering if I could make it get rid of any message that includes the word instead of the message being strictly ‘test’.
Solution – 1
The correct way to access the tag is just message.author.tag
, because user.username
is just a string and not an object. Here’s the User
object from the discord.js docs.
So your console.log statement should just be:
console.log(`Deleted message from ${msg.author.tag}`)