Discord Bot, problem while mentioning discord @users

429 Views Asked by At

The line where i want to mention the user with @

first part of the code1 2nn part of the code after the mention i want to apply2 I am developing a discord bot and I want the bot to mention the user that applied the command. I can show you more of the code. It is a bit complicated. I tried many times Mention.user and some other common answers but nothing happened.

ps. Edit: i provided 2 more images with the code if thats enough :)

2

There are 2 best solutions below

0
On BEST ANSWER

If you go to the discord.js site and click on Documentation in the top right, it will bring you to a page where you can learn about all of the objects in the discord.js api.

In your client.on("message"), message is defined, it is a message object, so to find that in the docs scroll down and look on the left side for Message, and click on it. You can now see all of the attributes that class has, it has an author, which the docs say is of type User. I have told you if you send a user object in a message, it will mention the user. So, send message.author and tada!

2
On

    As Tom Martin said, your current format is not compatible with Discord's API. There are a couple issues with this code.

    First off, unless you want unexpected results out of your for loops you should change to the ES6 standard of let to maintain lexical scope to only that block.

    Second in Javascript (JS) everything is an object. So essentially you must choose the method that returns the user object then either immediately use it or store it. How you do that is up to you, although, here is an example from discord.js themselves.

    Here is a link to the users method of the discord.js documentation. This will return a Collection (explanation of data structure) of all the User objects mapped by id. Hopefully this helped and good luck with your bot!