General Updates

This commit is contained in:
Ahmad 2024-03-03 17:43:26 -05:00
parent a67829c6f1
commit cdb82b771e
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
10 changed files with 161 additions and 129 deletions

View file

@ -5,6 +5,7 @@
"es6": true "es6": true
}, },
"parserOptions": { "parserOptions": {
"sourceType": "module",
"ecmaVersion": 2021 "ecmaVersion": 2021
}, },
"rules": { "rules": {

1
.vscode/launch.json vendored
View file

@ -24,4 +24,3 @@
} }
] ]
} }

View file

@ -1,4 +1,4 @@
import { SlashCommandBuilder, CommandInteraction } from 'discord.js'; import { SlashCommandBuilder, CommandInteraction } from "discord.js";
interface Command { interface Command {
data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">; data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
@ -7,10 +7,10 @@ interface Command {
const command: Command = { const command: Command = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('ping') .setName("ping")
.setDescription('Replies with Pong!'), .setDescription("Check the latency of the bot"),
execute: async (interaction) => { execute: async (interaction) => {
await interaction.reply(`Pong!`); await interaction.reply(`Pong! Latency: ${Date.now() - interaction.createdTimestamp}ms`);
}, },
}; };

View file

@ -2,6 +2,7 @@ import {
SlashCommandBuilder, SlashCommandBuilder,
CommandInteraction, CommandInteraction,
EmbedBuilder, EmbedBuilder,
CommandInteractionOptionResolver ,
} from "discord.js"; } from "discord.js";
interface Command { interface Command {
@ -12,19 +13,34 @@ interface Command {
const rulesEmbed = new EmbedBuilder() const rulesEmbed = new EmbedBuilder()
.setColor(0x0099ff) .setColor(0x0099ff)
.setTitle("Server Rules") .setTitle("Server Rules")
.setAuthor({ name: "Poixixel", iconURL: "https://cdn.discordapp.com/avatars/1052017329376071781/922947c726d7866d313744186c42ef49.webp" }) .setAuthor({
.setDescription("These are the rules for the server. Please read and follow them carefully.") name: "Poixixel",
iconURL:
"https://cdn.discordapp.com/avatars/1052017329376071781/922947c726d7866d313744186c42ef49.webp",
})
.setDescription(
"These are the rules for the server. Please read and follow them carefully."
)
.addFields( .addFields(
{ name: "Rule #1: Be respectful", value: "This means no mean, rude, or harassing comments. Treat others the way you want to be treated." }, {
{ name: '\u200B', value: '\u200B' }, name: "Rule #1: Be respectful",
{ name: "Rule #2: No inappropriate language", value: "All profanity language is prohibited in this server. Any derogatory language towards any user is prohibited. Swearing is not permitted in any channels." }, value:
{ name: '\u200B', value: '\u200B' } "This means no mean, rude, or harassing comments. Treat others the way you want to be treated.",
},
{ name: "\u200B", value: "\u200B" },
{
name: "Rule #2: No inappropriate language",
value:
"All profanity language is prohibited in this server. Any derogatory language towards any user is prohibited. Swearing is not permitted in any channels.",
},
{ name: "\u200B", value: "\u200B" }
//TODO Add all the rest of Poixpixel's rules here //TODO Add all the rest of Poixpixel's rules here
) )
.setTimestamp() .setTimestamp()
.setFooter({ .setFooter({
text: "Sent by the Poixpixel Bot", text: "Sent by the Poixpixel Bot",
iconURL: "https://cdn.discordapp.com/avatars/1052017329376071781/922947c726d7866d313744186c42ef49.webp", iconURL:
"https://cdn.discordapp.com/avatars/1052017329376071781/922947c726d7866d313744186c42ef49.webp",
}); });
const command: Command = { const command: Command = {
@ -34,7 +50,7 @@ const command: Command = {
execute: async (interaction) => { execute: async (interaction) => {
const channel = interaction.channel; const channel = interaction.channel;
channel?.send({ embeds: [rulesEmbed] }); channel?.send({ embeds: [rulesEmbed] });
await interaction.reply(`Here are the server rules:`); await interaction.reply({ content: 'The Rules Were Sent in the Current Channel', ephemeral: true });
}, },
}; };

View file

@ -1,4 +1,4 @@
import { SlashCommandBuilder, CommandInteraction } from 'discord.js'; import { SlashCommandBuilder, CommandInteraction } from "discord.js";
interface Command { interface Command {
data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">; data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
@ -7,10 +7,12 @@ interface Command {
const command: Command = { const command: Command = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('server') .setName("server")
.setDescription('Provides information about the server.'), .setDescription("Provides information about the server."),
execute: async (interaction) => { execute: async (interaction) => {
await interaction.reply(`This server is ${interaction?.guild?.name} and has ${interaction?.guild?.memberCount} members.`); await interaction.reply(
`The server name is ${interaction?.guild?.name} and it has ${interaction?.guild?.memberCount} members.`
);
}, },
}; };

View file

@ -1,4 +1,8 @@
import { SlashCommandBuilder, CommandInteraction, GuildMember } from 'discord.js'; import {
SlashCommandBuilder,
CommandInteraction,
GuildMember,
} from "discord.js";
interface Command { interface Command {
data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">; data: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">;
@ -7,13 +11,17 @@ interface Command {
const command: Command = { const command: Command = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('user') .setName("user")
.setDescription('Provides information about the user.'), .setDescription("Provides information about the user."),
execute: async (interaction) => { execute: async (interaction) => {
if (interaction.member instanceof GuildMember) { if (interaction.member instanceof GuildMember) {
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`); await interaction.reply(
`This command was run by ${interaction.user.username}, who joined this server on ${interaction.member.joinedAt}.`
);
} else { } else {
await interaction.reply(`This command was run by ${interaction.user.username}.`); await interaction.reply(
`This command was run by ${interaction.user.username}.`
);
} }
}, },
}; };

View file

@ -1,45 +1,49 @@
// Require the necessary discord.js classes import fs from "node:fs";
import fs from'node:fs'; import path from "node:path";
import path from 'node:path'; import { Client, Collection, Events, GatewayIntentBits } from "discord.js";
import { Client, Collection, Events, GatewayIntentBits } from'discord.js'; import config from "./config.json" assert { type: "json" };
import config from './config.json' assert { type: 'json' }; import { deployCommands } from "./util/deployCommand.js";
import { deployCommands } from './util/deployCommand.js';
const { token } = config; const { token } = config;
// Create a new client instance
const client: any = new Client({ intents: [GatewayIntentBits.Guilds] }); const client: any = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection(); client.commands = new Collection();
try { try {
const __dirname = path.resolve(); const __dirname = path.resolve();
const commandsPath = path.join(__dirname, '/target/commands/'); const commandsPath = path.join(__dirname, "/target/commands/");
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) { for (const file of commandFiles) {
const filePath = path.join('file://', commandsPath, file); const filePath = path.join("file://", commandsPath, file);
const commandModule = await import(filePath); const commandModule = await import(filePath);
const command = commandModule.default; const command = commandModule.default;
if (command instanceof Object && 'data' in command && 'execute' in command) { if (
command instanceof Object &&
"data" in command &&
"execute" in command
) {
client.commands.set(command.data.name, command); client.commands.set(command.data.name, command);
} else { } else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`); console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
);
} }
} }
} catch (error: any) { } catch (error: any) {
console.log(`Error while getting commands up: ${error}`) console.log(`Error while getting commands up: ${error}`);
} }
try { try {
await deployCommands(); await deployCommands();
} catch (error: any) { } catch (error: any) {
console.log(`Error while registering commands: ${error}`) console.log(`Error while registering commands: ${error}`);
} }
// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, (c: any) => { client.once(Events.ClientReady, (c: any) => {
console.log(`Ready! Logged in as ${c.user.tag}`); console.log(`Ready! Logged in as ${c.user.tag}`);
}); });
@ -59,12 +63,17 @@ client.on(Events.InteractionCreate, async (interaction: any) => {
} catch (error) { } catch (error) {
console.error(error); console.error(error);
if (interaction.replied || interaction.deferred) { if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true }); await interaction.followUp({
content: "There was an error while executing this command!",
ephemeral: true,
});
} else { } else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
} }
} }
}); });
// Log in to Discord with your client's token
client.login(token); client.login(token);

View file

@ -15,7 +15,6 @@ export const deployCommands = async () => {
try { try {
console.log(`Started refreshing ${commandFiles.length} application (/) commands.`); console.log(`Started refreshing ${commandFiles.length} application (/) commands.`);
// Prepare the commands array
const commands = commandFiles.map(async (file) => { const commands = commandFiles.map(async (file) => {
const filePath = path.join('file://', commandsPath, file); const filePath = path.join('file://', commandsPath, file);
const commandModule = await import(filePath); const commandModule = await import(filePath);
@ -29,10 +28,8 @@ export const deployCommands = async () => {
} }
}); });
// Filter out any null values from the commands array
const validCommands = await Promise.all(commands.filter(command => command !== null)); const validCommands = await Promise.all(commands.filter(command => command !== null));
// Use the provided way of registering commands
const data: any = await rest.put( const data: any = await rest.put(
Routes.applicationGuildCommands(clientId, guildId), Routes.applicationGuildCommands(clientId, guildId),
{ body: validCommands }, { body: validCommands },