convert js to ts
This commit is contained in:
parent
1a20ace1cc
commit
136fe81b50
6 changed files with 54 additions and 37 deletions
|
@ -1,9 +1,10 @@
|
|||
import { REST } from '@discordjs/rest';
|
||||
import { Routes } from 'discord-api-types/v9';
|
||||
import { Client } from 'discord.js';
|
||||
import { readdir } from 'fs/promises';
|
||||
|
||||
export default async client => {
|
||||
const rest = new REST({ version: '9' }).setToken(client.token);
|
||||
export default async (client: Client) => {
|
||||
const rest = new REST({ version: '9' }).setToken(client.token!);
|
||||
|
||||
const command_categories = (await readdir('./src/commands'))
|
||||
.filter(element => !element.endsWith('.js'));
|
||||
|
@ -31,7 +32,7 @@ export default async client => {
|
|||
)
|
||||
).flat(2);
|
||||
|
||||
return await rest.put(Routes.applicationCommands(client.user.id), {
|
||||
return await rest.put(Routes.applicationCommands(client.user!.id), {
|
||||
body: commands,
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { Client, CommandInteraction, Message } from 'discord.js';
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Pong!'),
|
||||
|
||||
interaction: async (interaction, client) => {
|
||||
|
||||
const sent = await interaction.reply({ content: 'Pinging...', fetchReply: true });
|
||||
interaction: async (interaction: CommandInteraction, client: Client) => {
|
||||
const sent = await interaction.reply({ content: 'Pinging...', fetchReply: true }) as Message;
|
||||
|
||||
interaction.editReply(
|
||||
`Roundtrip latency: \
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
export default (interaction, client) => {
|
||||
import { Client, Interaction } from 'discord.js';
|
||||
|
||||
export default (interaction: Interaction, client: Client) => {
|
||||
if (interaction.isCommand()) {
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
if (!command) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Client } from 'discord.js';
|
||||
import { readdir } from 'fs/promises';
|
||||
|
||||
export default async client => {
|
||||
export default async (client: Client) => {
|
||||
const events_categories = (await readdir('./src/events'))
|
||||
.filter(element => !element.endsWith('.js'));
|
||||
|
||||
|
@ -16,11 +17,11 @@ export default async client => {
|
|||
);
|
||||
|
||||
// Remove .js
|
||||
let event_type = event_file.split('.');
|
||||
if (event_type.pop() !== 'js') {
|
||||
let event_type_ext = event_file.split('.');
|
||||
if (event_type_ext.pop() !== 'js') {
|
||||
throw `Unknown file in ${event_category}: ${event_file}`;
|
||||
}
|
||||
event_type = event_type.join('.');
|
||||
const event_type = event_type_ext.join('.');
|
||||
|
||||
if (once) {
|
||||
return client.once(event_type, (...args) => {
|
||||
|
|
47
src/index.ts
47
src/index.ts
|
@ -1,6 +1,6 @@
|
|||
import loadClient from './utils/client.js';
|
||||
import loadEvents from './events/loader.js';
|
||||
import loadCommands from './commands/loader.js';
|
||||
import loadClient from './utils/client';
|
||||
import loadEvents from './events/loader';
|
||||
import loadCommands from './commands/loader';
|
||||
|
||||
const run = async () => {
|
||||
console.log('Starting Botanique...');
|
||||
|
@ -11,29 +11,28 @@ const run = async () => {
|
|||
}
|
||||
|
||||
// Client Discord.JS
|
||||
const client = await loadClient()
|
||||
.catch(() => {
|
||||
await loadClient()
|
||||
.then(async client => {
|
||||
console.log('Client ✅');
|
||||
await loadEvents(client)
|
||||
.then(_ => console.log('Events ✅'))
|
||||
.catch(() => {
|
||||
throw 'Events ❌';
|
||||
});
|
||||
|
||||
await client.login(client.config.token_discord);
|
||||
|
||||
await loadCommands(client)
|
||||
.then(_ => console.log('Commands ✅'))
|
||||
.catch(() => {
|
||||
throw 'Commands ❌';
|
||||
});
|
||||
|
||||
console.log(`Botanique "${client.user!.username}" ${client.config.version} started!`);
|
||||
})
|
||||
.catch(_ => {
|
||||
throw 'Client ❌';
|
||||
});
|
||||
if (client) {
|
||||
console.log('Client ✅');
|
||||
}
|
||||
|
||||
await loadEvents(client)
|
||||
.then(console.log('Events ✅'))
|
||||
.catch(() => {
|
||||
throw 'Events ❌';
|
||||
});
|
||||
|
||||
await client.login(client.config.token_discord);
|
||||
|
||||
await loadCommands(client)
|
||||
.then(console.log('Commands ✅'))
|
||||
.catch(() => {
|
||||
throw 'Commands ❌';
|
||||
});
|
||||
|
||||
console.log(`Botanique "${client.user.username}" ${client.config.version} started!`);
|
||||
};
|
||||
|
||||
run().catch(error => console.error(error));
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
import { Client, Collection, Intents } from 'discord.js';
|
||||
import { readFileSync } from 'fs';
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
|
||||
const { version } = JSON.parse(readFileSync('./package.json'));
|
||||
const { version } = JSON.parse(readFileSync('./package.json').toString());
|
||||
|
||||
declare module "discord.js" {
|
||||
export interface Client {
|
||||
config: {
|
||||
version: any,
|
||||
token_discord: any
|
||||
},
|
||||
commands: Collection<string, {
|
||||
data: SlashCommandBuilder,
|
||||
interaction: (interaction: CommandInteraction, client: Client) => any
|
||||
}>
|
||||
}
|
||||
}
|
||||
|
||||
// Création du client et de ses propriétés
|
||||
export default async () => {
|
||||
const client = new Client({
|
||||
const client: Client = new Client({
|
||||
intents: [
|
||||
Intents.FLAGS.GUILDS,
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue