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?
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.
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:
(Although I'd recommend you to use ID's instead of names, especially for the user)