first commit
This commit is contained in:
commit
0e9d8b2c24
11 changed files with 535 additions and 0 deletions
7
src/@types/discord.d.ts
vendored
Normal file
7
src/@types/discord.d.ts
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
import type { Client } from 'discord.js'
|
||||
|
||||
declare module 'discord.js' {
|
||||
export interface Client extends Client {
|
||||
commands: Collection<unknown, any>
|
||||
}
|
||||
}
|
10
src/commands/default/ping.ts
Normal file
10
src/commands/default/ping.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { SlashCommandBuilder, CommandInteraction } from "discord.js";
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
.setDescription("Replies with Pong!"),
|
||||
async execute(interaction: CommandInteraction) {
|
||||
await interaction.reply("Pong!");
|
||||
},
|
||||
};
|
21
src/events/interactionCreate.ts
Normal file
21
src/events/interactionCreate.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Events, Interaction } from "discord.js";
|
||||
|
||||
module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
async execute(interaction: Interaction) {
|
||||
if (interaction.isChatInputCommand()) {
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) {
|
||||
return console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
}
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
9
src/events/ready.ts
Normal file
9
src/events/ready.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { Events, Client } from "discord.js";
|
||||
|
||||
module.exports = {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
execute(client: Client) {
|
||||
console.log(`Ready! Logged in as ${client.user?.tag}`);
|
||||
},
|
||||
};
|
69
src/index.ts
Normal file
69
src/index.ts
Normal file
|
@ -0,0 +1,69 @@
|
|||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import "dotenv/config";
|
||||
import { Client, Collection, REST, Routes, RESTPutAPIApplicationCommandsResult } from 'discord.js';
|
||||
|
||||
const client: Client = new Client({
|
||||
intents: [],
|
||||
partials: []
|
||||
})
|
||||
|
||||
client.commands = new Collection();
|
||||
const commands = [];
|
||||
const foldersPath = path.join(__dirname, "commands");
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandFiles = fs
|
||||
.readdirSync(commandsPath)
|
||||
.filter((file) => file.endsWith(".ts"));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
if ("data" in command && "execute" in command) {
|
||||
client.commands.set(command.data.name, command);
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD_TOKEN : "");
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||
|
||||
const data = await rest.put(
|
||||
Routes.applicationCommands(process.env.BOT_ID ? process.env.BOT_ID : ""),
|
||||
{ body: commands }
|
||||
);
|
||||
|
||||
console.log(`Successfully reloaded ${commands.length} application (/) commands.`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
|
||||
const eventsPath = path.join(__dirname, "events");
|
||||
const eventFiles = fs
|
||||
.readdirSync(eventsPath)
|
||||
.filter((file) => file.endsWith(".ts"));
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const filePath = path.join(eventsPath, file);
|
||||
const event = require(filePath);
|
||||
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
else {
|
||||
client.on(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
}
|
||||
|
||||
client.login(process.env.DISCORD_TOKEN);
|
Loading…
Add table
Add a link
Reference in a new issue