ui changes
This commit is contained in:
@@ -1,23 +1,16 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { readDb } = require('../../backend/db.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'ping',
|
||||
description: 'Replies with Pong!',
|
||||
execute(interaction) {
|
||||
fs.readFile(path.join(__dirname, '../../backend/db.json'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return interaction.reply('An error occurred.');
|
||||
}
|
||||
const db = JSON.parse(data);
|
||||
const settings = db[interaction.guildId] || { pingCommand: false };
|
||||
const db = readDb();
|
||||
const settings = db[interaction.guildId] || { pingCommand: false };
|
||||
|
||||
if (settings.pingCommand) {
|
||||
interaction.reply('Pong!');
|
||||
} else {
|
||||
interaction.reply('The ping command is disabled on this server.');
|
||||
}
|
||||
});
|
||||
if (settings.pingCommand) {
|
||||
interaction.reply('Pong!');
|
||||
} else {
|
||||
interaction.reply('The ping command is disabled on this server.');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
require('dotenv').config({ path: '../backend/.env' });
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
const { REST, Routes } = require('discord.js');
|
||||
|
||||
const commands = [{
|
||||
name: 'ping',
|
||||
description: 'Replies with Pong!',
|
||||
}];
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
||||
|
||||
(async () => {
|
||||
const deployCommands = async (guildId) => {
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
console.log(`Started refreshing application (/) commands for guild ${guildId}.`);
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(process.env.DISCORD_CLIENT_ID, process.env.GUILD_ID),
|
||||
Routes.applicationGuildCommands(process.env.DISCORD_CLIENT_ID, guildId),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
console.log(`Successfully reloaded application (/) commands for guild ${guildId}.`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
module.exports = deployCommands;
|
||||
|
||||
26
discord-bot/events/guildMemberAdd.js
Normal file
26
discord-bot/events/guildMemberAdd.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const { Events } = require('discord.js');
|
||||
const { readDb } = require('../../backend/db.js');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildMemberAdd,
|
||||
async execute(member) {
|
||||
try {
|
||||
const db = readDb();
|
||||
const settings = db[`${member.guild.id}_welcome_leave`];
|
||||
|
||||
if (settings && settings.welcome && settings.welcome.enabled && settings.welcome.channel) {
|
||||
const channel = member.guild.channels.cache.get(settings.welcome.channel);
|
||||
if (channel) {
|
||||
try {
|
||||
const message = settings.welcome.message.replace('{user}', member.user.toString());
|
||||
await channel.send(message);
|
||||
} catch (error) {
|
||||
console.error(`Could not send welcome message to channel ${settings.welcome.channel} in guild ${member.guild.id}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in guildMemberAdd event for guild ${member.guild.id}:`, error);
|
||||
}
|
||||
},
|
||||
};
|
||||
26
discord-bot/events/guildMemberRemove.js
Normal file
26
discord-bot/events/guildMemberRemove.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const { Events } = require('discord.js');
|
||||
const { readDb } = require('../../backend/db.js');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildMemberRemove,
|
||||
async execute(member) {
|
||||
try {
|
||||
const db = readDb();
|
||||
const settings = db[`${member.guild.id}_welcome_leave`];
|
||||
|
||||
if (settings && settings.leave && settings.leave.enabled && settings.leave.channel) {
|
||||
const channel = member.guild.channels.cache.get(settings.leave.channel);
|
||||
if (channel) {
|
||||
try {
|
||||
const message = settings.leave.message.replace('{user}', member.user.tag);
|
||||
await channel.send(message);
|
||||
} catch (error) {
|
||||
console.error(`Could not send leave message to channel ${settings.leave.channel} in guild ${member.guild.id}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in guildMemberRemove event for guild ${member.guild.id}:`, error);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
const { ActivityType } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'ready',
|
||||
name: 'clientReady',
|
||||
once: true,
|
||||
execute(client) {
|
||||
console.log('ECS - Full Stack Bot Online!');
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
const { Client, GatewayIntentBits, Collection } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const deployCommands = require('./deploy-commands');
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers] });
|
||||
|
||||
client.commands = new Collection();
|
||||
|
||||
@@ -27,6 +28,10 @@ client.on('interactionCreate', async interaction => {
|
||||
}
|
||||
});
|
||||
|
||||
client.on('guildCreate', guild => {
|
||||
deployCommands(guild.id);
|
||||
});
|
||||
|
||||
const login = () => {
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
||||
}
|
||||
|
||||
13
discord-bot/package-lock.json
generated
13
discord-bot/package-lock.json
generated
@@ -9,9 +9,8 @@
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@discordjs/rest": "^2.3.0",
|
||||
"discord-api-types": "^0.37.92",
|
||||
"discord.js": "^14.15.3",
|
||||
"crypto-js": "^4.2.0",
|
||||
"discord.js": "^14.22.1",
|
||||
"dotenv": "^16.4.5"
|
||||
}
|
||||
},
|
||||
@@ -218,10 +217,10 @@
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/discord-api-types": {
|
||||
"version": "0.37.120",
|
||||
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.120.tgz",
|
||||
"integrity": "sha512-7xpNK0EiWjjDFp2nAhHXezE4OUWm7s1zhc/UXXN6hnFFU8dfoPHgV0Hx0RPiCa3ILRpdeh152icc68DGCyXYIw==",
|
||||
"node_modules/crypto-js": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
|
||||
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/discord.js": {
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"discord.js": "^14.15.3",
|
||||
"@discordjs/rest": "^2.3.0",
|
||||
"discord-api-types": "^0.37.92",
|
||||
"crypto-js": "^4.2.0",
|
||||
"discord.js": "^14.22.1",
|
||||
"dotenv": "^16.4.5"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user