Here as you see the code run at starting bot and get user invites from each server, and as you know need Administrator role but for example this bot is on 10 servers and one of these server turn off the ADMINISTRATOR role from bot and my bot got error and got Missing Access and then crash and just close I mean you must press any key
Here I want to check server perm I mean for one server and if the bot in the server didn't have role ignore it and not crash
module.exports = (client) => {
const invites = {} // { guildId: { memberId: count } }
const db = require("quick.db")
const getInviteCounts = async (message,guild) => {
return await new Promise((resolve) => {
guild.fetchInvites().then((invites) => {
const inviteCounter = {} // { memberId: count }
invites.forEach((invite) => {
const { uses, inviter } = invite
const { username, discriminator } = inviter
const name = `${username}#${discriminator}`
inviteCounter[name] = (inviteCounter[name] || 0) + uses
})
resolve(inviteCounter)
})
})
}
For discord.js v13 you need to use:
if(!message.guild.me.permissions.has("ADMINISTRATOR")) return message.reply(`I don't have ADMINISTRATOR permission`)