Search code examples
discorddiscord.js

Button Ban Command


Currently I'm trying to make a Ban Command which has Buttons to determine if a User should be banned or not. However, it now sets the Author and User as 'undefined' even though a User has been provided.

(Side Note, there's no Error showing up in the Console)

Here's what it currently looks like

Since the Code is pretty big, I decided to make a hastebin. Link: https://www.toptal.com/developers/hastebin/enolimecir.js


Solution

  • I've looked at your code and as you can see at your line 26 - 31 (.setDescription), thats where the undefined came from.

    .setDescription(`**User:** ${user.user.mention}\n**Moderator:** ${message.author.mention}\n**Reason:** ${reason}`)
    

    user.user.mention will not work at all because you have already defined the user but you defined a user again at the second user".user".mention, instead do it like this:

    **User:** <@${user.id}>
    

    and at the second undefined which is the moderator who requested the ban message.author.mention the message.author is correct but the .mention isn't, so what you're going to do instead is:

    **Moderator:** <@${message.author.id}>