Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Add event handling (broken)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gesugao-san committed Feb 21, 2022
1 parent 3dba77c commit 5616179
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion deploy-commands.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// node .\deploy-commands.js
// node ".\deploy-commands.js"

const fs = require('fs');
const { SlashCommandBuilder } = require('@discordjs/builders');
Expand Down
19 changes: 19 additions & 0 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

const { MessageEmbed } = require("discord.js");

module.exports = {
name: 'interactionCreate',
async execute(interaction, client) {
console.log(`${interaction.user.tag} in #${interaction.channel.name} triggered an interaction.`);
const command = client.commands.get(interaction.commandName);

if (!command) return;

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
},
};
10 changes: 10 additions & 0 deletions events/ready.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
name: 'ready',
once: true,
execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`);
//console.log(`Logged in as ${client.user.tag}!`);
},
};
25 changes: 19 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// 1: node index.js --trace-deprecation
// 2: node .\deploy-commands.js
// 1: node ".\index.js" --trace-deprecation
// 2: node "".\deploy-commands.js"
// https://discordjs.guide/creating-your-bot/, https://github.com/FiredragonPlayz/discord.js-tutorials

// Require the necessary discord.js classes
Expand All @@ -12,11 +12,23 @@ const cfg = require("./config.json");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
});
//client.removeAllListeners();

const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}

// When the client is ready, run this code (only once)
client.once('ready', () => {
/* client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
}); */

client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
Expand All @@ -28,8 +40,9 @@ for (const file of commandFiles) {
client.commands.set(command.data.name, command);
}

client.on('interactionCreate', async interaction => {
/* client.on('interactionCreate', async interaction => {
const command = client.commands.get(interaction.commandName);
console.log(`${interaction.user.tag} in #${interaction.channel.name} triggered an interaction.`);
if (!command) return;
Expand All @@ -39,7 +52,7 @@ client.on('interactionCreate', async interaction => {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
}); */

process.on('SIGINT', function() {
console.log("Caught interrupt signal."); //"Medical examination: Killed by сaughted interrupt signal."
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5616179

Please sign in to comment.