Andrew
Andrew

Reputation: 1575

Get channel/guild name by its id with discord.js

I want to retrieve the channel name, users list from a specific channel by its ID.

I'm getting the error Missing access

Error message:

DiscordAPIError: Missing Access
    at RequestHandler.execute (c:\Users\Viktor\Desktop\BattlefyParser\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async RequestHandler.push (c:\Users\Viktor\Desktop\BattlefyParser\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
    at async GuildManager.fetch (c:\Users\Viktor\Desktop\BattlefyParser\node_modules\discord.js\src\managers\GuildManager.js:247:18) {
  method: 'get',
  path: '/guilds/810614721694007316?with_counts=true',
  code: 50001,
  httpStatus: 403
}

My code:

const channelID = "810614721694007316";

client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}!`);

    client.guilds
        .fetch(channelID)
        .then((guild) => console.log(guild.name))
        .catch(console.error);
});

client.login("TOKEN");

Upvotes: 0

Views: 1305

Answers (1)

Josh Hales
Josh Hales

Reputation: 393

Your bot is missing the required permissions to perform that action. Make sure it has the View Channels permission when generating the OAuth2 token in the Discord Developer panel.

Upvotes: 1

Related Questions