Skip to content

Commit

Permalink
feat(command-registry): allow filtering guildIds from the `Failed to …
Browse files Browse the repository at this point in the history
…fetch guild commands` log (#368)

Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
  • Loading branch information
favna and vladfrangu committed Jan 24, 2022
1 parent 92b5542 commit f330d83
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/lib/SapphireClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ export interface SapphireClientOptions {
* @default false
*/
disableMentionPrefix?: boolean;

/**
* Whenever starting the bot process Sapphire may report errors when failing to fetch guild commands.
* One of the causes for this can be when a bot was invited to a server without the `application.commands` scope.
*
* Normally this produce a log in the console at the WARN level, however because bot lists have a tendency to invite your
* bot specifically without the scope to ensure that your Chat Input and Context Menu commands do not show up as usable commands
* in that server, you may want to include their guild ids in this list.
*
* By adding ids to this list, whenever a guild id matches one of the ids in the list no warning log message will be emitted for that guild.
*
* Note that this specifically applies to the warning log:
*
* > ApplicationCommandRegistries: Failed to fetch guild commands for guild \<guild name\> (\<guild id\>). Make sure to authorize your application with the "applications.commands" scope in that guild.
*/
preventFailedToFetchLogForGuildIds?: string[];
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/lib/utils/application-commands/getNeededParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ async function fetchGuildCommands(commands: ApplicationCommandManager) {
const guildCommands = await commands.fetch({ guildId });
map.set(guildId, guildCommands);
} catch (err) {
container.logger.warn(
`ApplicationCommandRegistries: Failed to fetch guild commands for guild "${guild.name}" (${guildId}).`,
'Make sure to authorize your application with the "applications.commands" scope in that guild.'
);
if (!container.client.options.preventFailedToFetchLogForGuildIds?.includes(guildId)) {
container.logger.warn(
`ApplicationCommandRegistries: Failed to fetch guild commands for guild "${guild.name}" (${guildId}).`,
'Make sure to authorize your application with the "applications.commands" scope in that guild.'
);
}
}
}

Expand Down

0 comments on commit f330d83

Please sign in to comment.