Discord.js: How do I get my bot to mention groups

Created on 9 Jul 2016  路  5Comments  路  Source: discordjs/discord.js

var Discord = require("discord.js");

var bot = new Discord.Client();

bot.on("message", function (message)
{
    var input = message.content.toUpperCase();

    if(input === "HELP!")
    {
        bot.sendMessage(message, "@admins are on the way!");
    }
    if(input === "PING")
    {
        bot.sendMessage(message, "Pong!");
    }
    if(input === "WHO MADE SHADOWBOT?")

    {
        bot.sendMessage(message, "@Techmo3014#7140 made me.")
    }

});

bot.loginWithToken("my token");

That is my code, could any of you edit it so the @admins and @techmo3014#7140 work?

question (please use Discord instead)

Most helpful comment

In Discord in general you can mention people with <@ID> and _mentionable_ roles with <@&ID>. Discord.js has helper functions for that though, so <userObject>.mention() and <roleObject>.mention() works. Even better, these objects .toString() will return that function, and node calls .toString() on anything that's interpreted as a string!

So to answer your question you'd first have to get the objects and then you can simply insert them in your string:

var Discord = require("discord.js");

var bot = new Discord.Client();

bot.on("message", function (message)
{
    var input = message.content.toUpperCase();

    if(input === "HELP!")
    {
        let adminRoleObject = message.server.roles.get('name', 'admins');
        bot.sendMessage(message, `${adminRoleObject} are on the way!`);
    }
    if(input === "PING")
    {
        bot.sendMessage(message, "Pong!");
    }
    if(input === "WHO MADE SHADOWBOT?")

    {
        let ownerUserObject = message.server.members.get('name', 'Techmo3014');
        bot.sendMessage(message, `${ownerUserObject} made me.`);
    }

});

bot.loginWithToken("my token");

(Although I'd recommend you to use ID's instead of names, especially for the user)

All 5 comments

In Discord in general you can mention people with <@ID> and _mentionable_ roles with <@&ID>. Discord.js has helper functions for that though, so <userObject>.mention() and <roleObject>.mention() works. Even better, these objects .toString() will return that function, and node calls .toString() on anything that's interpreted as a string!

So to answer your question you'd first have to get the objects and then you can simply insert them in your string:

var Discord = require("discord.js");

var bot = new Discord.Client();

bot.on("message", function (message)
{
    var input = message.content.toUpperCase();

    if(input === "HELP!")
    {
        let adminRoleObject = message.server.roles.get('name', 'admins');
        bot.sendMessage(message, `${adminRoleObject} are on the way!`);
    }
    if(input === "PING")
    {
        bot.sendMessage(message, "Pong!");
    }
    if(input === "WHO MADE SHADOWBOT?")

    {
        let ownerUserObject = message.server.members.get('name', 'Techmo3014');
        bot.sendMessage(message, `${ownerUserObject} made me.`);
    }

});

bot.loginWithToken("my token");

(Although I'd recommend you to use ID's instead of names, especially for the user)

Why doesn't it work

https://discord.gg/S8mDK Give us a visit :eyes:

message.server.member returns for me "Cannot get member of undefined"

This issue is over a year old.

Also like the label suggests, please use our Discord server to ask questions.
The issue tracker is only for bug reports and enhancement suggestions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Brawaru picture Brawaru  路  3Comments

Dmitry221060 picture Dmitry221060  路  3Comments

shukriadams picture shukriadams  路  3Comments

iCrawl picture iCrawl  路  3Comments

DatMayo picture DatMayo  路  3Comments