Version 3.0 sortie, fusion avec JujulBot
This commit is contained in:
26
src/index.ts
26
src/index.ts
@@ -1,28 +1,29 @@
|
||||
// PACKAGES
|
||||
import { Client, Collection, GatewayIntentBits, REST, Routes, ChatInputCommandInteraction, AutocompleteInteraction, ButtonInteraction } from 'discord.js'
|
||||
import { Player } from 'discord-player'
|
||||
import { connection } from 'mongoose'
|
||||
import { connection, Connection } from 'mongoose'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import 'dotenv/config'
|
||||
|
||||
import pjson from '../package.json'
|
||||
console.log('Running on version', pjson.version)
|
||||
|
||||
export interface Command {
|
||||
// CUSTOM TYPES
|
||||
interface CConnection extends Connection {
|
||||
once: (event: string, listener: (...args: any[]) => void) => void
|
||||
on: (event: string, listener: (...args: any[]) => void) => void
|
||||
}
|
||||
interface Command {
|
||||
name: string
|
||||
description: string
|
||||
data: any
|
||||
autocompleteRun: (interaction: AutocompleteInteraction) => any
|
||||
execute: (interaction: ChatInputCommandInteraction) => any
|
||||
}
|
||||
export interface Button {
|
||||
interface Button {
|
||||
name: string
|
||||
description: string
|
||||
id: string
|
||||
execute: (interaction: ButtonInteraction) => any
|
||||
}
|
||||
|
||||
declare module 'discord.js' {
|
||||
export interface Client {
|
||||
commands: Collection<unknown, Command>
|
||||
@@ -69,6 +70,8 @@ let commandsTotal = 0
|
||||
|
||||
let commandFolders = fs.readdirSync(path.join(__dirname, './commands'))
|
||||
commandFolders.forEach(folder => {
|
||||
if (folder === 'salonpostam' && process.env.DISCORD_APP_ID === '660961595006124052') return
|
||||
|
||||
let folderPath = path.join(__dirname, './commands', folder)
|
||||
let commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.ts'))
|
||||
commandsTotal += commandFiles.length
|
||||
@@ -83,6 +86,7 @@ commandFolders.forEach(folder => {
|
||||
commandsParsed++
|
||||
|
||||
if (commandsParsed === commandsTotal) {
|
||||
console.log(`[INFO] ${commandsParsed} commands parsed.`)
|
||||
// COMMANDS REGISTRATION
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN as string);
|
||||
(async () => {
|
||||
@@ -107,8 +111,8 @@ let eventClientFiles = fs.readdirSync(path.join(__dirname, './events/client')).f
|
||||
eventClientFiles.forEach(async file => {
|
||||
let event = await import(path.join(__dirname, './events/client', file))
|
||||
event = event.default
|
||||
if (event.once) client.once(event.name, (...args) => { event.execute(...args) })
|
||||
else client.on(event.name, (...args) => { event.execute(...args) })
|
||||
if (event.once) client.once(event.name, (...args: any[]) => { event.execute(...args) })
|
||||
else client.on(event.name, (...args: any[]) => { event.execute(...args) })
|
||||
})
|
||||
|
||||
// PLAYER EVENTS HANDLING
|
||||
@@ -125,8 +129,8 @@ let eventsMongo = fs.readdirSync(path.join(__dirname, './events/mongo')).filter(
|
||||
eventsMongo.forEach(async file => {
|
||||
let event = await import(path.join(__dirname, './events/mongo', file))
|
||||
event = event.default
|
||||
if (event.once) connection.once(event.name, (...args) => { event.execute(...args, client) })
|
||||
else connection.on(event.name, (...args) => { event.execute(...args, client) })
|
||||
if (event.once) (connection as CConnection).once(event.name, (...args: any[]) => { event.execute(...args, client) })
|
||||
else (connection as CConnection).on(event.name, (...args: any[]) => { event.execute(...args, client) })
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user