bug resolutions
This commit is contained in:
parent
ec835b03e3
commit
ac0672f13a
7 changed files with 53 additions and 42 deletions
|
@ -3,6 +3,7 @@
|
|||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tsx watch src",
|
||||
"build": "tsc",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { SlashCommandBuilder, ChatInputCommandInteraction } from "discord.js";
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("ping")
|
||||
.setDescription("Replies with Pong!"),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Events, Interaction } from "discord.js";
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
name: Events.InteractionCreate,
|
||||
async execute(interaction: Interaction) {
|
||||
if (interaction.isChatInputCommand()) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Events, Message } from "discord.js";
|
||||
module.exports = {
|
||||
|
||||
export default {
|
||||
name: Events.MessageCreate,
|
||||
async execute(message: Message) {
|
||||
//console.log(message.content);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Events, Client } from "discord.js";
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
execute(client: Client) {
|
||||
|
|
79
src/index.ts
79
src/index.ts
|
@ -9,32 +9,56 @@ const client: Client = new Client({
|
|||
})
|
||||
|
||||
client.commands = new Collection();
|
||||
const commands = [];
|
||||
const foldersPath = path.join(__dirname, "commands");
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
const commands: any[] = [];
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandFiles = fs
|
||||
.readdirSync(commandsPath)
|
||||
.filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
|
||||
async function loadCommands() {
|
||||
const foldersPath = './src/commands';
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
|
||||
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.`);
|
||||
}
|
||||
}
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = `./src/commands/${folder}`;
|
||||
const commandFiles = fs
|
||||
.readdirSync(commandsPath)
|
||||
.filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const filePath = `./commands/${folder}/${file}`;
|
||||
const command = await import(filePath.replace(".ts", ".js"));
|
||||
if ("data" in command.default && "execute" in command.default) {
|
||||
client.commands.set(command.default.data.name, command.default);
|
||||
commands.push(command.default.data.toJSON());
|
||||
}
|
||||
else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function loadEvents() {
|
||||
const eventsPath = "./src/events";
|
||||
const eventFiles = fs
|
||||
.readdirSync(eventsPath)
|
||||
.filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const filePath = `./events/${file}`;
|
||||
const event = await import(filePath.replace(".ts", ".js"));
|
||||
|
||||
if (event.default.once) {
|
||||
client.once(event.default.name, (...args) => event.default.execute(...args));
|
||||
}
|
||||
else {
|
||||
client.on(event.default.name, (...args) => event.default.execute(...args));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD_TOKEN : "");
|
||||
|
||||
(async () => {
|
||||
await loadCommands();
|
||||
await loadEvents();
|
||||
try {
|
||||
console.log(`Started refreshing ${commands.length} application (/) commands.`);
|
||||
|
||||
|
@ -49,21 +73,4 @@ const rest = new REST().setToken(process.env.DISCORD_TOKEN ? process.env.DISCORD
|
|||
}
|
||||
})();
|
||||
|
||||
const eventsPath = path.join(__dirname, "events");
|
||||
const eventFiles = fs
|
||||
.readdirSync(eventsPath)
|
||||
.filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
|
||||
|
||||
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);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"target": "ES5",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"resolveJsonModule": true,
|
||||
"strict": true,
|
||||
"outDir": "./dist",
|
||||
"skipLibCheck": true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue