Common questions


  • <client> is a placeholder for the Client object, such as const client = new Discord.Client();.
  • <message> is a placeholder for the Message object, such as client.on('message', message => { ... });.
  • <guild> is a placeholder for the Guild object, such as <message>.guild or <client>.guilds.get('<id>').

For a more detailed explanation on the notations commonly used in this guide, the docs, and the support server, see here.


How do I ban a user?

const user = <message>.mentions.users.first();

How do I kick a user?

const member = <message>.mentions.members.first();

How do I add a role to a guild member?

const role = <guild>.roles.find(role => === '<role name>');
const member = <message>.mentions.members.first();

How do I check if a guild member has a certain role?

const member = <message>.mentions.members.first();
if (member.roles.some(role => === '<role name>')) {
	// ...

How do I limit a command to a single user?

if (<message> === '<id>') {
	// ...

Bot Configuration

How do I set my username?


How do I set my avatar?

<client>.user.setAvatar('<url or path>');

How do I set my playing status?


How do I set my status to "Watching ..." or "Listening to ..."?

<client>.user.setActivity('<activity>', { type: 'WATCHING' });
<client>.user.setActivity('<activity>', { type: 'LISTENING' });


If you would like to set your activity upon startup, you must place the <client>.user.setActivity() method in a ready event listener (<client>.on('ready', () => {});).


If you're using a selfbot to change your activity, you won't be able to view the status change, but other users will.


<client>.user.setActivity() will only work in v11.3 and above. You can check your version with npm ls discord.js and update with npm install discord.js. You can still use <client>.user.setGame(), but it is deprecated as of v11.3, and has been removed in v12.


How do I send a message to a certain channel?

const channel = <client>.channels.get('<id>');

How do I DM a certain user?

const user = <client>.users.get('<id>');


If you want to DM the user who sent the message, you can use <message>.author.send().

How do I tag a certain user in a message?

const user = <message>.mentions.users.first();
<message>.channel.send(`Hi, ${user}.`);
<message>.channel.send('Hi, <@user id>.');


If you want to tag the user who sent the message, you can use <message>.reply(). For example: <message>.reply('hi.') would result in @User, hi.. If you want to insert the tag elsewhere, you can store <message>.author as your user variable and use the original example.


Tags inside certain areas of an embed may display correctly, but will not actually ping the user. Tags inside other certain areas of an embed will display the raw string instead (e.g. <@123456789012345678>).

How do I prompt the user for additional input?

<message>.channel.send('Please enter more input.').then(() => {
	const filter = m => <message> ===;

	<message>.channel.awaitMessages(filter, { time: 60000, maxMatches: 1, errors: ['time'] })
		.then(messages => {
			<message>.channel.send(`You've entered: ${messages.first().content}`);
		.catch(() => {
			<message>.channel.send('You did not enter any input!');


If you want to learn more about this syntax or want to learn about reaction collectors as well, check out this dedicated guide page for collectors!

How do I react to the message my bot sent?

<message>.channel.send('My message to react to.').then(sentMessage => {
	sentMessage.react('<emoji id>');


If you want to learn more about reactions, check out this dedicated guide on reactions!

How do I create a restart command?



process.exit() will only kill your Node process, but when using PM2, it will restart the process whenever it gets killed. You can read our guide on PM2 here.


Be sure to limit this to your own ID so that other users can't restart your bot!

What is the difference between a User and a GuildMember?

A lot of users get confused as to what the difference between Users and GuildMembers is. The simple answer is that a User represents a global Discord user and a GuildMember represents a Discord user on a specific server. That means only GuildMembers can have permissions, roles, and nicknames, for example, because all of these things are server-bound information that could be different on each server that user is in.

Last Updated: 5/12/2019, 10:52:22 AM