MemberRemove call when I kick my bot

When I kick my bot of a server, I think that the event "MemberRemive" is called, and it makes a bug :
node_modules\@discordjs\rest\dist\index.js:640
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[50013]: Missing Permissions
node_modules\@discordjs\rest\dist\index.js:640
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[50013]: Missing Permissions
That's possible ? If yes how to fix it thx
32 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:640
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[50013]: Missing Permissions
at handleErrors (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:1021:23)
at async SequentialHandler.queueRequest (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:862:14)
at async REST.request (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:1387:22)
at async Guild.fetchAuditLogs (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\discord.js\src\structures\Guild.js:759:18) {
requestBody: { files: undefined, json: undefined },
rawError: { message: 'Missing Permissions', code: 50013 },
code: 50013,
status: 403,
method: 'GET',
url: 'https://discord.com/api/v10/guilds/1059551378592235520/audit-logs?limit=1&action_type=24'
}
:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:640
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[50013]: Missing Permissions
at handleErrors (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:1021:23)
at async SequentialHandler.queueRequest (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:862:14)
at async REST.request (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\@discordjs\rest\dist\index.js:1387:22)
at async Guild.fetchAuditLogs (c:\Users\virgi\OneDrive\Documents\Projets perso\discord\altara\bots-altara\Thenix - Modération\node_modules\discord.js\src\structures\Guild.js:759:18) {
requestBody: { files: undefined, json: undefined },
rawError: { message: 'Missing Permissions', code: 50013 },
code: 50013,
status: 403,
method: 'GET',
url: 'https://discord.com/api/v10/guilds/1059551378592235520/audit-logs?limit=1&action_type=24'
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
Yes, I saw it but why he looks the fetch audit logs on a server where he isn't
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
how he wan detect an event "MembeRemove", he is the remove member xD yes
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2y ago
event (event) Client#guildDelete Emitted whenever a guild kicks the client or the guild is deleted/left.
Virgile
VirgileOP2y ago
I did it
const { Events } = require('discord.js');
const Guild = require('../../models/guild');

module.exports = {
name: Events.GuildDelete,
once: true,
execute(client) {

// Delete the guild with the ID of the guild that has just been deleted
Guild.destroy({ where: { id: client.id }}).then(() => {
console.log('DB: guild deleted');
}
).catch(err => {
console.log(err);
}
)
},
};
const { Events } = require('discord.js');
const Guild = require('../../models/guild');

module.exports = {
name: Events.GuildDelete,
once: true,
execute(client) {

// Delete the guild with the ID of the guild that has just been deleted
Guild.destroy({ where: { id: client.id }}).then(() => {
console.log('DB: guild deleted');
}
).catch(err => {
console.log(err);
}
)
},
};
but the error comes before that event takes effect
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
The bot does ban, kick, ... logs
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2y ago
property Guild#available Whether the guild is available to access. If it is not available, it indicates a server outage
Virgile
VirgileOP2y ago
I will try to do that thx mmmh, I puted before each access on fetching audit log
if (user.guild.available === false) return console.log('logBan: Guild not available');
if (user.guild.available === false) return console.log('logBan: Guild not available');
but it changes nothing
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
It depends but when the bot is kick, yes XD
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
there is a lot of files, what do you want to see
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
I start in JavaScript, I warn you it's surely not nice to see x) wait
Virgile
VirgileOP2y ago
better like that
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
The name changes anything, or you tell me this for the sake of clarity
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
I thought to myself ahah Yes, but how can I do the check with another way
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
It's only a theory, i dont know why when the bot is kick, he try to read fetchlog audit
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Virgile
VirgileOP2y ago
It does not work with that if anyone have an idea for this error :/ I can give read access to the github
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server