JS Discord Bot Get Role

Hell Protection picture Hell Protection · Jan 17, 2018 · Viewed 20.4k times · Source

I'm trying to get a role without using messages, like:

     const Discord = require('discord.js');
     const Bot = new Discord.Client();
     const Role = Discord.roles.find('name,'Exemple')

     Role.delete()

Is this possible to do that?

Answer

Wright picture Wright · Jan 17, 2018

Yes you can but you will need to have the guild id you want to get the role from. Also, you should put that part in the ready event.

const discord = require("discord.js");
const client = new discord.Client();

client.on("ready", () => {
    console.log("Bot online!");
    const guild = client.guilds.get("The_server_id");
    const role = guild.roles.find("name", "Your_role_name");

    console.log(`Found the role ${role.name}`);
})