Track invite origin

Hello developers! I am trying to set up a tracker for different invite sources for my bot but I keep getting a Missing permissions error. The invite URL works fine for every use case. What kind of permission do I need to be able to fetch commands. Current intents: GatewayIntentBits.Guilds, GatewayIntentBits.GuildInvites
const invites = await guild.invites.fetch(); // This is where it fails

let inviteSource = "unknown";
invites.forEach((invite) => {
if (invite.url.includes("source=game")) {
inviteSource = "in-game directory";
} else if (invite.url.includes("source=app")) {
inviteSource = "Bot";
} else if (invite.url.includes("source=topgg")) {
inviteSource = "top.gg";
}
});
const invites = await guild.invites.fetch(); // This is where it fails

let inviteSource = "unknown";
invites.forEach((invite) => {
if (invite.url.includes("source=game")) {
inviteSource = "in-game directory";
} else if (invite.url.includes("source=app")) {
inviteSource = "Bot";
} else if (invite.url.includes("source=topgg")) {
inviteSource = "top.gg";
}
});
11 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
souji
souji2mo ago
that endpoint requires the manage guild permission not sure what you think you are doing here discord doesn't have a source in the server invites
Lambros
LambrosOP2mo ago
Thanks but wouldn't manage guild permission make people hesistant in adding the bot?
souji
souji2mo ago
not sure what you expect me to say; that's the limitation the api enforces if you want to fetch invites, that's what the app needs
Lambros
LambrosOP2mo ago
No description
Lambros
LambrosOP2mo ago
This is the one you are referring to right? I have custom URLs thsr contain source obviously wouldn't post without it I tried adding the permission and re inviting the bot still didn't work
souji
souji2mo ago
those will not be saved by discord
Lambros
LambrosOP2mo ago
Oh Well if get past the permission issue I will worry about that later
souji
souji2mo ago
the permission issue is that the bot does not have a role with the manage server permission on the server you are trying to fetch invites from
Lambros
LambrosOP2mo ago
Makes sense i remember couple years ago roles were created automatically for bots that joined I guess they changed that
souji
souji2mo ago
the invite link can include permissions, if they do a role with those permissions is created, yes that's not guaranteed, people can just invite your app with another invite link
Want results from more Discord servers?
Add your server