mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
WIP working example
This commit is contained in:
1 parent
6ebf7b9bd3
commit
3be362f096
4 files changed
+15
-38
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, Message, SlashCommandBuilder } from 'discord.js';
|
||||||
import { BaseCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes';
|
import { BaseCommandInteraction, BaseSlashCommandParams } from '../../../types/interactionTypes';
|
||||||
|
|
||||||
export class TestCommandInteraction extends BaseCommandInteraction {
|
export class TestCommandInteraction extends BaseCommandInteraction {
|
||||||
@@ -7,16 +7,18 @@ export class TestCommandInteraction extends BaseCommandInteraction {
|
|||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute(params: BaseSlashCommandParams): Promise<void> {
|
async execute(params: BaseSlashCommandParams): Promise<Message<boolean> | void> {
|
||||||
const { executionId, interaction } = params;
|
const { executionId, interaction } = params;
|
||||||
const logger = this.getLogger('test.ts', 'test', executionId, interaction);
|
const logger = this.getLogger('test.js', executionId, interaction);
|
||||||
|
|
||||||
logger.info('test command executed');
|
logger.info('test command executed');
|
||||||
logger.info(`${interaction.user.tag} executed test command`);
|
logger.info(`${interaction.user.tag} executed test command`);
|
||||||
logger.info(`Execution ID: ${executionId}`);
|
logger.info(`Execution ID: ${executionId}`);
|
||||||
|
|
||||||
logger.info(this.embedOptions.icons.success + ' Icon success from config.');
|
logger.info(this.embedOptions.icons.success + ' Icon success from config.');
|
||||||
return;
|
return await interaction.editReply({
|
||||||
|
embeds: [new EmbedBuilder().setDescription('It works!').setColor(this.embedOptions.colors.success)]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,17 +72,10 @@ export class CustomError extends Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class BaseInteraction {
|
abstract class BaseInteraction {
|
||||||
protected getLoggerBase(
|
protected getLoggerBase(module: string, source: string, executionId: string, interaction: Interaction): Logger {
|
||||||
module: string,
|
|
||||||
source: string,
|
|
||||||
name: string,
|
|
||||||
executionId: string,
|
|
||||||
interaction: Interaction
|
|
||||||
): Logger {
|
|
||||||
return loggerModule.child({
|
return loggerModule.child({
|
||||||
source: source,
|
source: source,
|
||||||
module: module,
|
module: module,
|
||||||
name: name,
|
|
||||||
executionId: executionId,
|
executionId: executionId,
|
||||||
shardId: interaction.guild?.shardId,
|
shardId: interaction.guild?.shardId,
|
||||||
guildId: interaction.guild?.id
|
guildId: interaction.guild?.id
|
||||||
@@ -108,15 +101,15 @@ export abstract class BaseCommandInteraction extends BaseInteraction {
|
|||||||
isBeta?: boolean
|
isBeta?: boolean
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.data = data;
|
this.data = data.setDMPermission(false).setNSFW(false);
|
||||||
this.isSystemCommand = isSystemCommand || false;
|
this.isSystemCommand = isSystemCommand || false;
|
||||||
this.isNew = isNew || false;
|
this.isNew = isNew || false;
|
||||||
this.isBeta = isBeta || false;
|
this.isBeta = isBeta || false;
|
||||||
this.embedOptions = config.get('embedOptions');
|
this.embedOptions = config.get('embedOptions');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getLogger(source: string, name: string, executionId: string, interaction: Interaction): Logger {
|
protected getLogger(source: string, executionId: string, interaction: Interaction): Logger {
|
||||||
return super.getLoggerBase('slashCommand', source, name, executionId, interaction);
|
return super.getLoggerBase('slashCommand', source, executionId, interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract execute(params: BaseSlashCommandParams): Promise<Message<boolean> | void>;
|
abstract execute(params: BaseSlashCommandParams): Promise<Message<boolean> | void>;
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
const commandFiles: string[] = fs
|
const commandFiles: string[] = fs
|
||||||
.readdirSync(path.resolve(`./dist/interactions/commands/${folder}`))
|
.readdirSync(path.resolve(`./dist/interactions/commands/${folder}`))
|
||||||
@@ -59,18 +58,12 @@ const rest: REST = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_
|
|||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
// TODO: create commandModule type
|
// TODO: create commandModule type
|
||||||
const commandModule = await import(`../interactions/commands/${folder}/${file}`);
|
const { default: command } = await import(`../interactions/commands/${folder}/${file}`);
|
||||||
const command = commandModule.default;
|
|
||||||
command.isSystemCommand
|
command.isSystemCommand
|
||||||
? systemCommands.push(command.data.toJSON())
|
? systemCommands.push(command.data.toJSON())
|
||||||
: slashCommands.push(command.data.toJSON());
|
: slashCommands.push(command.data.toJSON());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
const commandModule = await import('../interactions/commands/player/test.js');
|
|
||||||
const command = commandModule.default;
|
|
||||||
slashCommands.push(command.data.toJSON());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`);
|
logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`);
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export const registerClientCommands = async ({ client, executionId }: RegisterCl
|
|||||||
logger.debug('Registering client commands...');
|
logger.debug('Registering client commands...');
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
/*
|
|
||||||
const commandFolders: string[] = fs.readdirSync(path.resolve('./dist/interactions/commands'));
|
const commandFolders: string[] = fs.readdirSync(path.resolve('./dist/interactions/commands'));
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
logger.trace(`Registering client commands for folder '${folder}'...`);
|
logger.trace(`Registering client commands for folder '${folder}'...`);
|
||||||
@@ -32,12 +31,10 @@ export const registerClientCommands = async ({ client, executionId }: RegisterCl
|
|||||||
// delete command from require cache
|
// delete command from require cache
|
||||||
delete require.cache[require.resolve(`../interactions/commands/${folder}/${file}`)];
|
delete require.cache[require.resolve(`../interactions/commands/${folder}/${file}`)];
|
||||||
|
|
||||||
// register command
|
// load command and register it to client.commands collection
|
||||||
//const command = require(`../interactions/commands/${folder}/${file}`);
|
const { default: command } = await import(`../interactions/commands/${folder}/${file}`);
|
||||||
const commandModule = await import(`../interactions/commands/${folder}/${file}`);
|
client.commands.delete(command.data.name);
|
||||||
|
client.commands.set(command.data.name, command);
|
||||||
client.commands.delete(commandModule.default.data.name);
|
|
||||||
client.commands.set(commandModule.default.data.name, commandModule.default);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
||||||
@@ -46,15 +43,7 @@ export const registerClientCommands = async ({ client, executionId }: RegisterCl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
const commandModule = await import('../interactions/commands/player/test.js');
|
|
||||||
const command = commandModule.default;
|
|
||||||
|
|
||||||
logger.info(command.data);
|
|
||||||
client.commands.set('test', command);
|
|
||||||
|
|
||||||
logger.trace('Registering client commands complete.');
|
logger.trace('Registering client commands complete.');
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user