Added logtochannel function and moved to it
This commit is contained in:
24
src/utils/functions/logtochannel.ts
Normal file
24
src/utils/functions/logtochannel.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { guildid, onlineLogChannel, botLogChannel, guildLogChannel, errorLogChannel } from "../../../config/options.json"
|
||||
import { Guild, MessageCreateOptions, TextChannel } from "discord.js"
|
||||
import Illegitimate from "../Illegitimate"
|
||||
|
||||
const channels = {
|
||||
online: onlineLogChannel,
|
||||
bot: botLogChannel,
|
||||
guild: guildLogChannel,
|
||||
error: errorLogChannel
|
||||
}
|
||||
|
||||
type Channel = keyof typeof channels
|
||||
|
||||
export default async function logToChannel(channel: Channel, message: MessageCreateOptions): Promise<void|null> {
|
||||
const guild = Illegitimate.client.guilds.cache.get(guildid) as Guild
|
||||
|
||||
const logChannel = guild.channels.cache.get(channels[channel]) as TextChannel
|
||||
if (!logChannel) {
|
||||
console.log(`[ERROR] Could not find channel used for ${channel} logging.`)
|
||||
return
|
||||
}
|
||||
|
||||
await logChannel.send(message)
|
||||
}
|
||||
Reference in New Issue
Block a user