노드가 CONNECTED 상태가 아닐 때 joinVoiceChannel이 throw 되어 fire-and-forget handleMessage에서 처리되지 않은 Promise 거부로 번지던 문제 수정. - LavalinkManager.hasReadyNode() 추가 - channelJoin에서 노드 미연결 시 안내 임베드 반환 + join try/catch - messageCreate의 handleMessage 호출에 .catch 추가 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
85 lines
3.5 KiB
TypeScript
85 lines
3.5 KiB
TypeScript
import { ChannelType, Message } from "discord.js";
|
|
import { client, handler, lavalinkManager } from "../index";
|
|
import { Config } from "../utils/Config";
|
|
import { Logger } from "../utils/Logger";
|
|
import { DB } from "../utils/Database";
|
|
import { getVoiceChannel } from "../utils/music/Channel";
|
|
import { channelJoin } from "../commands/join";
|
|
|
|
const cmdErr = (message: Message, commandName: string | undefined | null): void => {
|
|
if (!commandName) return;
|
|
if (message.channel.type !== ChannelType.GuildText) return;
|
|
message.channel.send({ embeds: [ client.mkembed({
|
|
description: `\` ${commandName} \` 이라는 명령어를 찾을 수 없습니다.`,
|
|
footer: { text: `${Config.prefix}help를 입력해 명령어를 확인해주세요.` },
|
|
color: "DarkRed",
|
|
}) ] }).then(m => client.msgDelete(m, 1));
|
|
}
|
|
|
|
export const messageCreate = async (message: Message): Promise<void> => {
|
|
if (message.author.bot || message.channel.type === ChannelType.DM) return;
|
|
if (!message.content.startsWith(client.prefix)) {
|
|
handleMessage(message).catch((err) => {
|
|
Logger.error(`[messageCreate] handleMessage 처리 중 에러: ${String(err)}`);
|
|
});
|
|
return;
|
|
}
|
|
|
|
const content = message.content.slice(client.prefix.length).trim();
|
|
const args = content.split(/ +/g);
|
|
const commandName = args.shift()?.toLocaleLowerCase() || "";
|
|
const command = handler.commands.get(commandName) || handler.commands.find((cmd) => cmd.aliases.includes(commandName));
|
|
try {
|
|
if (!command || !command.messageRun) {
|
|
if (!commandName || commandName.replace(/\;| +/g,"").length === 0) return;
|
|
cmdErr(message, commandName);
|
|
return client.msgDelete(message, 0, true);
|
|
}
|
|
command.messageRun(message, args);
|
|
client.msgDelete(message, 0, true);
|
|
} catch(err: any) {
|
|
if (Config.debug) Logger.error(err);
|
|
cmdErr(message, commandName);
|
|
return client.msgDelete(message, 0, true);
|
|
}
|
|
}
|
|
|
|
async function handleMessage(message: Message): Promise<void> {
|
|
if (!message.guild?.id) return;
|
|
if (!message.member?.user?.id) return;
|
|
if (message.channel.type !== ChannelType.GuildText) return;
|
|
const gdb = DB.guild.get(message.guild.id);
|
|
if (!gdb?.channel_id) return;
|
|
if (gdb.channel_id !== message.channel.id) return;
|
|
let player = lavalinkManager.getPlayer(message.guild.id);
|
|
const voiceChannel = getVoiceChannel(message.member);
|
|
if (!player) {
|
|
if (!voiceChannel) {
|
|
message.channel.send({ embeds: [ client.mkembed({
|
|
author: {
|
|
name: message.member.nickname ?? message.member.user.displayName,
|
|
iconURL: message.member.displayAvatarURL({}) ?? undefined,
|
|
},
|
|
title: "음성채널을 찾을수 없습니다.",
|
|
description: "음성채널에 들어가서 사용해주세요.",
|
|
color: "DarkRed",
|
|
}) ] }).then(m => client.msgDelete(m, 1));
|
|
return client.msgDelete(message, 100, true);
|
|
}
|
|
player = (await channelJoin(message.guild, voiceChannel.id)).player;
|
|
}
|
|
if (!player) {
|
|
message.channel.send({ embeds: [ client.mkembed({
|
|
author: {
|
|
name: message.member.nickname ?? message.member.user.displayName,
|
|
iconURL: message.member.displayAvatarURL({}) ?? undefined,
|
|
},
|
|
title: "세션을 찾을수 없습니다.",
|
|
description: "다시 시도해주세요.",
|
|
color: "DarkRed",
|
|
}) ] }).then(m => client.msgDelete(m, 1));
|
|
return client.msgDelete(message, 100, true);
|
|
}
|
|
lavalinkManager.search(message.guild.id, message.content.trim(), message.member.user.id, player);
|
|
return client.msgDelete(message, 100, true);
|
|
} |