Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
How can I make my discord bot assign roles to users (discord js)

Here is my code:

How can I assign roles to users with my discord js bot?

How can I make my discord bot assign roles to users (discord js)

I want it so that when I type !addrole a role gets added

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.on('ready', () => {
  console.log('Bot Online');
});

var prefix = "!"

client.on(`message`, message => {
  if(message.content.startsWith(prefix + "addrole"))
  {
    //ADD ROLE HERE
  }

});

client.on('ready', () => {
  client.user.setActivity(`!help`, { type: "PLAYING" });
});

client.login('TOKEN');
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

First you need to find the role you want to add:

const guild = message.guild;
let role = message.mentions.roles.first() || guild.roles.cache.find(role => role.id === message.content.substring(1))

Then you add the role using:

const member = message.member
member.roles.add(role);
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!