question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I get my bot to mention groups

See original GitHub issue
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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
mnlkrscommented, Jul 9, 2016

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)

1reaction
ghostcommented, Jul 9, 2016

Why doesn’t it work

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I get a discord bot to mention a role and a user?
So, to mention a user you need to use their user ID <@USER_ID> / <@!USER_ID> and for a role it is similarly <@&ROLE_ID>...
Read more >
Create conversation bots for channel or group chat - Teams
Work with mentions ... Every message to your bot from a group or channel contains an @mention with its name in the message...
Read more >
How to Add a Telegram Bot to Telegram Group (2022 Tutorial)
In this tutorial, I will explain how you can add a Telegram chatbot to your Telegram group and automatically reply to messages in...
Read more >
How to Add Bots to a Discord Server - Business Insider
How to set up MEE6 as a welcoming bot on Discord · 1. Click the Welcome option. · 2. Select what you want...
Read more >
Bots Tutorial - GroupMe Developers
Using a bot is as easy as registering a member name and optional avatar url. Then you use the secret key you get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found