DJS 봇 템플릿 v2022.704.0 출시!
22365 단어 nodetypescriptdiscordnews
...
import logger from './utils/logger.js';
...
process.on(`rejectionHandled`, (error) => logger.error(error));
process.on(`unhandledRejection`, (error) => logger.error(error));
process.on(`uncaughtException`, (error) => logger.error(error));
import { Client, Interaction } from 'discord.js';
import { inject, injectable } from 'tsyringe';
import type { EventInterface } from '../client/interfaces/event.js';
import type { InteractionInterface } from '../client/interfaces/interaction.js';
import { INTERACTIONS } from '../client/tokens.js';
import logger from '../utils/logger.js';
@injectable()
export default class SelectMenuInteractionCreateEvent implements EventInterface {
public name = `Select Menu Interaction Create`;
public event = `interactionCreate`;
public constructor(
private readonly client: Client<true>,
@inject(INTERACTIONS) private readonly interactions: Map<string, InteractionInterface>,
) {}
public execute() {
this.client.on(this.event, async (interaction: Interaction<`cached`>) => {
try {
if (!interaction.isSelectMenu()) {
return;
}
const menu_ = this.interactions.get(interaction.customId);
if (!menu_) {
return;
}
await menu_.execute(interaction);
} catch (e) {
const error = e as Error;
logger.error(error, error.message);
}
});
}
}
@@ -0,0 +1,22 @@
import type { SelectMenuInteraction } from 'discord.js';
import type { InteractionInterface } from '../client/interfaces/interaction.js';
import logger from '../utils/logger.js';
export default class ExampleSelectMenuInteraction implements InteractionInterface {
public readonly name = `Example Select Menu`;
public readonly customId = `selectMenuId`;
public async execute(interaction: SelectMenuInteraction<`cached`>) {
try {
const values_ = interaction.values;
await interaction.reply({
content: `${values_.join(`\n`)}`,
ephemeral: true,
});
} catch (e) {
const error = e as Error;
logger.error(error, error.message);
}
}
}
@@ -8,16 +8,18 @@ import config from '../../utils/config.js';
* @returns {EmbedBuilder}
*/
export function exampleCommandEmbed(interaction: ChatInputCommandInteraction<`cached`>): EmbedBuilder {
const options_ = interaction.options;
const string_: string = options_.getString(`string`)!;
const integer_: string = options_.getInteger(`integer`)?.toString() ?? `n/a`;
const number_: string = options_.getNumber(`number`)?.toString() ?? `n/a`;
const boolean_: string = options_.getBoolean(`boolean`)?.toString() ?? `n/a`;
const user_: string = options_.getUser(`user`)?.toString() ?? `n/a`;
const member_: string = options_.getMember(`user`)?.toString() ?? `n/a`;
const channel_: string = options_.getChannel(`channel`)?.toString() ?? `n/a`;
const role_: string = options_.getRole(`role`)?.toString() ?? `n/a`;
const mentionable_: string = options_.getMentionable(`mentionable`)?.toString() ?? `n/a`;
const choice_: string = options_.getString(`choice`) ?? `n/a`;
return new EmbedBuilder()
.setColor(config.color.primary)
@@ -29,12 +31,12 @@ export function exampleCommandEmbed(interaction: ChatInputCommandInteraction<`ca
{ name: `String`, value: `${string_}`, inline: true },
{ name: `Integer`, value: `${integer_}`, inline: true },
{ name: `Number`, value: `${number_}`, inline: true },
{ name: `Boolean`, value: `${boolean_}`, inline: true },
{ name: `User`, value: `${user_}`, inline: true },
{ name: `Member`, value: `${member_}`, inline: true },
{ name: `Channel`, value: `${channel_}`, inline: true },
{ name: `Role`, value: `${role_}`, inline: true },
{ name: `Mentionable`, value: `${mentionable_}`, inline: true },
{ name: `Choice`, value: `${choice_}`, inline: true },
);
}
전체 변경 로그는 GitHub에서 사용할 수 있습니다. 2022.704.0
Reference
이 문제에 관하여(DJS 봇 템플릿 v2022.704.0 출시!), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/twiistrz/djs-bot-template-v20227010-released-kj4텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)