Fix permission errors when reading audit logs (#25)

Note: This PR depends on #24

This error does not actually break any functionality but it both
clutters the logs and may cause problems at scale if we start hitting
the API error limit
pull/26/head
Samuel Shuert 3 years ago committed by GitHub
commit 9a1dfc23d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,7 @@ import { toHexArray } from "./calculate.js";
import { promisify } from "util";
import generateKeyValueList from "./generateKeyValueList.js";
import client from "./client.js";
import {DiscordAPIError} from "discord.js";
const wait = promisify(setTimeout);
@ -84,9 +85,15 @@ export const Logger = {
event: Discord.GuildAuditLogsResolvable,
delay?: number
): Promise<Discord.GuildAuditLogsEntry[]> {
if (!guild.members.me?.permissions.has("ViewAuditLog")) return [];
await wait(delay ?? 250);
try {
const auditLog = (await guild.fetchAuditLogs({ type: event })).entries.map((m) => m);
return auditLog as Discord.GuildAuditLogsEntry[];
} catch (e) {
if (e instanceof DiscordAPIError) return [];
throw e;
}
},
async log(log: LoggerOptions): Promise<void> {
if (!(await isLogging(log.hidden.guild, log.meta.calculateType))) return;

Loading…
Cancel
Save