getting guild object
anyone knows how can I check if any kind of event happened and get the guild object?
my bot only works on guilds so direct messages can be ignored.
my bot only works on guilds so direct messages can be ignored.
import { Client } from "discord.js";
import { readdirSync } from "fs";
import { join } from "path";
import { color } from "../functions";
import { BotEvent } from "../types";
module.exports = (client: Client) => {
let eventsDir = join(__dirname, "../events")
readdirSync(eventsDir).forEach(file => {
if (!file.endsWith(".js")) return;
let event: BotEvent = require(`${eventsDir}/${file}`).default
event.once ?
client.once(event.name, (...args) => event.execute(...args))
:
client.on(event.name, (...args) => {
console.log(...args);
const isApiOffline = checkApiAvailability();
if (isApiOffline) {
//pseudo code
//smthg like this but I dont want to make a switch case over all event types to get the guild object.
const guildId = args[0].getEvent().guild;
const guild = client.guilds.cache.get(guildId);
const owner = guild?.fetchOwner();
owner.send("API is offline");
}
});
})
}
function checkApiAvailability() {
return false;
}import { Client } from "discord.js";
import { readdirSync } from "fs";
import { join } from "path";
import { color } from "../functions";
import { BotEvent } from "../types";
module.exports = (client: Client) => {
let eventsDir = join(__dirname, "../events")
readdirSync(eventsDir).forEach(file => {
if (!file.endsWith(".js")) return;
let event: BotEvent = require(`${eventsDir}/${file}`).default
event.once ?
client.once(event.name, (...args) => event.execute(...args))
:
client.on(event.name, (...args) => {
console.log(...args);
const isApiOffline = checkApiAvailability();
if (isApiOffline) {
//pseudo code
//smthg like this but I dont want to make a switch case over all event types to get the guild object.
const guildId = args[0].getEvent().guild;
const guild = client.guilds.cache.get(guildId);
const owner = guild?.fetchOwner();
owner.send("API is offline");
}
});
})
}
function checkApiAvailability() {
return false;
}