fix: migrate all commands & src to @fluxerjs native API

- Replace replyEmbed/sendEmbed/editEmbed with reply/send/edit
  across all 33 command files and 5 src/ files
- Remove unnecessary .toJSON() on EmbedBuilder (Fluxer auto-converts)
- Fix voice channel type checks: channel_type === "VoiceChannel" → type === 2
- Add missing edit() and send() methods to Message/ChannelContext wrappers
- Fix filter command: reactions now update per page on navigation

Closes channel cache crash (guild.channels.cache.keys undefined)
This commit is contained in:
NoLogicAlan committed 2026-05-05 20:09:25 +03:00
1 parent 19820e7209
commit 85f11fe34b
38 files changed
+395 -314

No files matched your search

+8 -8
View File
@@ -135,7 +135,7 @@ export class Option {
return this.userRegex.test(i) || this.idRegex.test(i);
case "channel":
if (i === undefined) return false;
return this.channelRegex.test(i) || this.idRegex.test(i) || client.channels.cache.some(c => c.name === i);
return this.channelRegex.test(i) || this.idRegex.test(i) || client.channels.some(c => c.name === i);
case "voiceChannel": {
if (!i) return false;
const results = this.channelRegex.exec(i) ?? this.idRegex.exec(i);
@@ -145,9 +145,9 @@ export class Option {
if (guildId === "eval") return (results) ? results.groups["id"] : i;
const voiceTypes = [2, 13]; // GuildVoice and GuildStageVoice
const byName = msg?.guild?.channels?.cache?.find(c => c.name === i && voiceTypes.includes(c.type));
const byName = msg?.guild?.channels?.find(c => c.name === i && voiceTypes.includes(c.type));
const cObj = results
? client.channels.cache.get(results.groups["id"])
? client.channels.get(results.groups["id"])
: (byName ?? null);
return cObj ? voiceTypes.includes(cObj.type) : false;
}
@@ -178,7 +178,7 @@ export class Option {
}
case "channel": {
const results = this.channelRegex.exec(i) ?? this.idRegex.exec(i);
const channel = client.channels.cache.find(c => c.name === i);
const channel = client.channels.find(c => c.name === i);
return results ? results.groups["id"] : (channel ? channel.id : null);
}
case "voiceChannel": {
@@ -186,7 +186,7 @@ export class Option {
const guildId = msg?.channel?.guildId ?? msg?.guildId;
if (guildId === "eval") return r ? r.groups["id"] : (i || null);
const voiceTypes = [2, 13];
const c = msg?.guild?.channels?.cache?.find(c => c.name === i && voiceTypes.includes(c.type));
const c = msg?.guild?.channels?.find(c => c.name === i && voiceTypes.includes(c.type));
return r ? r.groups["id"] : (c ? c.id : null);
}
}
@@ -390,7 +390,7 @@ export class CommandHandler extends EventEmitter {
this.helpHandler = new HelpHandler(this);
this.helpCommand = "help";
this.replyHandler = (message, msg) => {
msg.replyEmbed(this.format(message, msg.channel.channel.guildId));
msg.reply(this.format(message, msg.channel.channel.guildId));
};
this.messages.onMessage(this.messageHandler.bind(this));
}
@@ -720,13 +720,13 @@ export class CommandLoader {
result.catch(e => {
const id = Utils.uid();
logger.error("Error running command; error id #" + id, e);
data.message.replyEmbed("An error occurred. Error id: `#" + id + "`");
data.message.reply("An error occurred. Error id: `#" + id + "`");
});
}
} catch (e) {
const id = Utils.uid();
logger.error("Error running command; error id #" + id, e);
data.message.replyEmbed("An error occurred. Error id: `#" + id + "`");
data.message.reply("An error occurred. Error id: `#" + id + "`");
}
});
}
+27 -11
View File
@@ -133,8 +133,8 @@ export class MessageHandler {
get(id) {
// channel.messages is a MessageManager — @fluxerjs/core may not expose it.
// Guard with optional chaining so the loop is a no-op if the property is absent.
for (const channel of this.client.channels.cache.values()) {
const msg = channel.messages?.cache?.get?.(id) ?? null;
for (const channel of this.client.channels.values()) {
const msg = channel.messages?.get?.(id) ?? null;
if (msg) return new Message(msg, this);
}
return null;
@@ -164,7 +164,7 @@ export class MessageHandler {
* @returns {Channel}
*/
getChannel(id) {
const c = this.client.channels.cache.get(id);
const c = this.client.channels.get(id);
return new Channel(c, this);
}
@@ -237,7 +237,7 @@ export class MessageHandler {
}
}
return builder.toJSON();
return builder;
}
#createEmbed(text, message, options = {}) {
@@ -384,7 +384,7 @@ export class MessageHandler {
const currPage = { n: 0 };
const send = () => builder.getPage(currPage.n);
const m = await msg.replyEmbed(send());
const m = await msg.reply(send());
if (!m) return;
m.message.react(arrows[0]).catch(() => {});
@@ -396,13 +396,13 @@ export class MessageHandler {
} else {
currPage.n = Math.min(pages.length - 1, currPage.n + 1);
}
m.editEmbed(send()).catch(() => {});
m.edit(send()).catch(() => {});
});
// Auto-close after 5 minutes
setTimeout(() => {
unobserve();
m.editEmbed(send() + "\nSession closed - Changing pages **won't work** from here.").catch(() => {});
m.edit(send() + "\nSession closed - Changing pages **won't work** from here.").catch(() => {});
}, 5 * 60 * 1000);
}
@@ -482,6 +482,14 @@ export class Channel {
return this.handler.sendMessage(this.channel, content);
}
/**
* @param {string|Object} content
* @returns {Promise<Message>}
*/
send(content) {
return this.handler.sendMessage(this.channel, content);
}
/**
* @param {string|Object} content
* @param {Object} embedOptions
@@ -582,6 +590,15 @@ export class Message {
editEmbed(content, embedOptions = {}) {
return this.handler.editEmbed(this.message, content, embedOptions);
}
/**
* @param {string|Object} content
* @param {Object} embedOptions
* @returns {Promise<Message>}
*/
edit(content, embedOptions = {}) {
return this.handler.editEmbed(this.message, content, embedOptions);
}
}
export class PageBuilder {
@@ -731,8 +748,7 @@ export class RichPaginator {
.setAuthor({ name: tab.header })
.setTitle(tab.title)
.setDescription(content)
.setFooter({ text: footerParts.join(" ") })
.toJSON();
.setFooter({ text: footerParts.join(" ") });
}
async send() {
@@ -1142,13 +1158,13 @@ export class HelpCommand {
c.aliases.some(a => a.toLowerCase() === word.toLowerCase())
);
if (!found) {
msg.replyEmbed(`❌ Unknown command \`${word}\`. Use \`${prefix}help\` to browse.`);
msg.reply(`❌ Unknown command \`${word}\`. Use \`${prefix}help\` to browse.`);
return;
}
currCmd = found;
}
if (currCmd) {
msg.replyEmbed(this._commands.helpHandler.getCommandHelp(currCmd, msg));
msg.reply(this._commands.helpHandler.getCommandHelp(currCmd, msg));
}
return;
}
+38 -11
View File
@@ -23,7 +23,7 @@ import { PROVIDER_NAMES } from "./constants/providers.mjs";
/** Emit a plain embed payload so listeners can send it directly */
function mkEmbed(desc) {
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc).toJSON()] };
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc)] };
}
/** NodeLink default password — centralised so it doesn't need to be hardcoded in two places. */
@@ -593,13 +593,36 @@ export default class Player extends EventEmitter {
}
} catch (_) {}
try {
const channel = this.client?.channels?.cache?.get(this._channelId);
const members = channel?.members;
if (members) {
const iter = typeof members.values === "function" ? members.values() : Object.values(members);
for (const entry of iter) {
const isBot = entry?.user?.bot ?? entry?.member?.user?.bot ?? false;
if (!isBot) return true;
// @fluxerjs channels do NOT have a .members property.
// Use the guild's member manager and filter by voice state instead.
const guild = this.client?.guilds?.get?.(this._guildId);
if (guild?.members) {
for (const member of guild.members.values()) {
// GuildMember doesn't expose voice channelId directly in @fluxerjs,
// so fall through to the voice_states raw data check below.
if (!member?.user?.bot) {
// We can't determine channel from member alone — skip here
// and rely on _observedVoiceUsers or voice_states instead.
}
}
}
// Fallback: iterate raw voice_states on the guild object.
const voiceStates = guild?.voice_states;
if (voiceStates) {
const entries = Array.isArray(voiceStates)
? voiceStates
: typeof voiceStates.values === "function"
? voiceStates.values()
: Object.values(voiceStates);
for (const state of entries) {
const stateChannelId = String(state?.channelId ?? state?.channel_id ?? "").replace(/\D/g, "");
if (stateChannelId === cleanChan) {
const userId = String(state?.userId ?? state?.user_id ?? "");
// Check if user is a bot — look up via members or observedVoiceUsers
const member = guild?.members?.get?.(userId);
const isBot = member?.user?.bot ?? false;
if (!isBot) return true;
}
}
}
} catch (_) {}
@@ -724,7 +747,7 @@ export default class Player extends EventEmitter {
}
_setupMediaPlayerMonitoring() {
// No-op: recovery is fully handled by connection.on("disconnected") in join().
// No-op: recovery is fully handled by connection.on("disconnect") in join().
}
async _cleanupMediaPlayer() {
@@ -1066,7 +1089,7 @@ export default class Player extends EventEmitter {
this._isJoining = true;
try {
const channel = this.client?.channels?.cache?.get(channelId);
const channel = this.client?.channels?.get?.(channelId);
if (!channel) throw new Error(`Channel not found: ${channelId}`);
if (this.connection) {
@@ -1161,7 +1184,11 @@ export default class Player extends EventEmitter {
});
});
connection.on("disconnected", () => {
// @fluxerjs VoiceConnection / LiveKitRtcConnection emits "disconnect",
// NOT "disconnected" (Discord.js naming). Using the wrong event name meant
// this handler was silently never registered — voice disconnect recovery
// was completely broken.
connection.on("disconnect", () => {
if (this.connection !== connection) {
try { connection.removeAllListeners(); connection.destroy(); } catch (_) {}
return;
+43 -36
View File
@@ -17,7 +17,7 @@ import { getGlobalColor } from "./MessageHandler.mjs";
/** Helper — build a plain embed payload from a description string */
function mkEmbed(desc) {
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc).toJSON()] };
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc)] };
}
function cleanId(value) {
@@ -123,10 +123,22 @@ export class PlayerManager {
const sendUserUpdates = (event) => {
if (!this.dashboard?.enabled) return;
const channelId = getPlayerChannelId(player, context.channelId);
const channel = player.client?.channels?.cache?.get(channelId);
if (!channel?.members) return;
for (const member of channel.members.values()) {
if (member.user?.bot) continue;
const channel = player.client?.channels?.get(channelId);
const guild = player.client?.guilds?.get(cleanId(player._guildId ?? context.guildId));
if (!guild) return;
const voiceStates = guild.voice_states ?? guild.voiceStates ?? null;
if (!voiceStates) return;
const entries = Array.isArray(voiceStates)
? voiceStates
: typeof voiceStates.values === "function"
? [...voiceStates.values()]
: Object.values(voiceStates);
for (const state of entries) {
if (!state?.channelId && !state?.channel_id) continue;
const stateChannelId = cleanId(state.channelId ?? state.channel_id);
if (stateChannelId !== channelId) continue;
const member = guild.members?.get?.(state.userId ?? state.user_id);
if (!member?.user || member.user?.bot) continue;
const details = {
event,
guildId: cleanId(player._guildId ?? context.guildId),
@@ -249,9 +261,9 @@ export class PlayerManager {
try {
const guild =
this.commands.client?.guilds?.cache?.get?.(guildId) ??
this.commands.client?.guilds?.cache?.get?.(cleanGuild);
const voiceStates = guild?.voice_states ?? guild?.voiceStates?.cache ?? guild?.voiceStates ?? null;
this.commands.client?.guilds?.get?.(guildId) ??
this.commands.client?.guilds?.get?.(cleanGuild);
const voiceStates = guild?.voice_states ?? guild?.voiceStates ?? null;
if (voiceStates) {
if (!Array.isArray(voiceStates) && typeof voiceStates === "object") {
const direct = voiceStates[userId];
@@ -282,7 +294,6 @@ export class PlayerManager {
const liveGuildPlayers = [...this.playerMap.entries()].filter(([channelId, player]) => {
const fallbackChannel =
this.commands.client?.channels?.get?.(channelId) ??
this.commands.client?.channels?.cache?.get?.(channelId) ??
null;
return getPlayerGuildId(player, fallbackChannel) === cleanGuild;
});
@@ -339,7 +350,7 @@ export class PlayerManager {
first[1].textChannel = message.channel;
return first[1];
}
message.replyEmbed(mkEmbed(`⚠️ You need to join a voice channel to use this command.`));
message.reply(mkEmbed(`⚠️ You need to join a voice channel to use this command.`));
return null;
}
@@ -363,7 +374,7 @@ export class PlayerManager {
return this.settings.getServer(guildId)?.get("prefix") ?? "%";
} catch (_) { return "%"; }
})();
message.replyEmbed(mkEmbed(`⚠️ I'm already playing in ${channelList}. Join that channel or use \`${prefix}play\` to start music in your channel.`));
message.reply(mkEmbed(`⚠️ I'm already playing in ${channelList}. Join that channel or use \`${prefix}play\` to start music in your channel.`));
return null;
}
@@ -372,7 +383,7 @@ export class PlayerManager {
// Auto-detect failed — fall back to interactive channel selection prompt
return this.promptVC(message);
}
message.replyEmbed(mkEmbed("⚠️ Please join a voice channel first."));
message.reply(mkEmbed("⚠️ Please join a voice channel first."));
return null;
}
@@ -403,11 +414,10 @@ export class PlayerManager {
const guildId = getMessageGuildId(msg);
const cleanGuildId = cleanId(guildId);
const allChannels = cleanGuildId
? [...(this.commands.client?.channels?.values?.() ??
this.commands.client?.channels?.cache?.values?.() ?? [])]
? [...(this.commands.client?.channels?.values?.() ?? [])]
.filter(c => {
const channelGuildId = cleanId(c.guildId ?? c.guild?.id ?? c.server_id ?? c.serverId);
const isVoice = c.channel_type === "VoiceChannel" || c.type === "VoiceChannel" || c.type === 2;
const isVoice = c.type === 2;
return channelGuildId === cleanGuildId && isVoice;
})
: [];
@@ -421,7 +431,7 @@ export class PlayerManager {
channelArr.forEach((c, i) => { channelSelection += `${i + 1}. <#${c._id ?? c.id}>\n`; });
}
const selectionMsg = await msg.replyEmbed(mkEmbed(
const selectionMsg = await msg.reply(mkEmbed(
(channelSelection ? channelSelection + "\n**..or**" : "Please") +
" send a message with the voice channel! (Mention/Id/Name)\nSend 'x' to cancel."
));
@@ -437,7 +447,7 @@ export class PlayerManager {
const timeout = setTimeout(() => {
cleanup();
msg.replyEmbed(mkEmbed("⏱️ Voice selection timed out."));
msg.reply(mkEmbed("⏱️ Voice selection timed out."));
resolve(false);
}, 30_000);
@@ -462,12 +472,12 @@ export class PlayerManager {
if (content === "x") {
clearTimeout(timeout);
cleanup();
m.replyEmbed(mkEmbed("Cancelled!"));
m.reply(mkEmbed("Cancelled!"));
resolve(false);
return;
}
if (!this.commands.validateInput("voiceChannel", m.content, m)) {
m.replyEmbed(mkEmbed("Invalid voice channel. Try again or type `x`."));
m.reply(mkEmbed("Invalid voice channel. Try again or type `x`."));
return;
}
const channel = this.commands.formatInput("voiceChannel", m.content, m);
@@ -500,12 +510,12 @@ export class PlayerManager {
}
const player = cid ? this.playerMap.get(cid) : null;
if (!player) return msg.replyEmbed(mkEmbed("I'm not in a voice channel."));
if (!player) return msg.reply(mkEmbed("I'm not in a voice channel."));
const activeChannelId = String(player._channelId ?? cid).replace(/\D/g, "") || cid;
this.playerMap.delete(activeChannelId);
if (activeChannelId !== cid) this.playerMap.delete(cid);
await msg.replyEmbed(mkEmbed("✅ Successfully Left"));
await msg.reply(mkEmbed("✅ Successfully Left"));
await player.leave();
player.destroy();
}
@@ -521,21 +531,18 @@ export class PlayerManager {
* @param {Function} [cb]
*/
initPlayer(message, cid, cb = () => {}) {
const channel = this.commands.client?.channels?.get(cid) ??
this.commands.client?.channels?.cache?.get(cid);
const channel = this.commands.client?.channels?.get(cid);
if (!channel) {
return message.replyEmbed(mkEmbed(
return message.reply(mkEmbed(
`Couldn't find the channel \`${cid}\`\nUse the help command to learn more about this.`
));
}
const isVoice = channel.channel_type === "VoiceChannel" ||
channel.type === "VoiceChannel" ||
channel.type === 2;
const isVoice = channel.type === 2;
if (!isVoice) {
return message.replyEmbed(mkEmbed("❌ Please join a **voice channel** first before using this command!"));
return message.reply(mkEmbed("❌ Please join a **voice channel** first before using this command!"));
}
const cleanChannelId = cleanId(cid);
@@ -544,7 +551,7 @@ export class PlayerManager {
if (existing) {
existing.textChannel = message.channel;
cb(existing);
return message.replyEmbed(mkEmbed(`Already joined <#${cid}>.`));
return message.reply(mkEmbed(`Already joined <#${cid}>.`));
}
const player = new Player(this.config.token, {
@@ -582,7 +589,7 @@ export class PlayerManager {
const desc = is247
? `Left channel <#${activeChannelId}> because of inactivity.`
: `Left channel <#${activeChannelId}> because of inactivity.\nIf you want me to stay in voice, use \`${prefix}247 on/auto\``;
ch?.sendEmbed(mkEmbed(desc));
ch?.send(mkEmbed(desc));
this.playerMap.delete(activeChannelId);
if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId);
if (homeChannelId !== activeChannelId) this.playerMap.delete(homeChannelId);
@@ -598,16 +605,16 @@ export class PlayerManager {
const disabled = raw === false || raw === 0 ||
["false","0","no","off","disable"].includes(String(raw).toLowerCase().trim());
if (disabled) return;
ch?.sendEmbed(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m));
ch?.send(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m));
});
this.playerMap.set(cleanChannelId, player);
(async () => {
const statusMsg = await message.replyEmbed(mkEmbed("⏳ Joining Channel..."));
const statusMsg = await message.reply(mkEmbed("⏳ Joining Channel..."));
try {
await player.join(cid);
await statusMsg.editEmbed(mkEmbed(`✅ Successfully joined <#${cid}>`));
await statusMsg.edit(mkEmbed(`✅ Successfully joined <#${cid}>`));
const guildId = cleanId(channel.guildId ?? getMessageGuildId(message));
if (guildId) {
@@ -620,7 +627,7 @@ export class PlayerManager {
cb(player);
} catch (err) {
await statusMsg.editEmbed(mkEmbed(`❌ Failed to join: ${err.message}`)).catch(() => {});
await statusMsg.edit(mkEmbed(`❌ Failed to join: ${err.message}`)).catch(() => {});
this.playerMap.delete(cleanChannelId);
player.destroy();
}
@@ -643,12 +650,12 @@ export class PlayerManager {
? this.playerMap.get(cleanChannelId) ??
[...this.playerMap.values()].find((entry) => getPlayerChannelId(entry) === cleanChannelId)
: null;
if (!player) return msg.replyEmbed(mkEmbed("I'm not in a voice channel."));
if (!player) return msg.reply(mkEmbed("I'm not in a voice channel."));
const activeChannelId = getPlayerChannelId(player, cleanChannelId) || cleanChannelId;
this.playerMap.delete(activeChannelId);
if (activeChannelId !== cleanChannelId) this.playerMap.delete(cleanChannelId);
await msg.replyEmbed(mkEmbed("✅ Successfully Left"));
await msg.reply(mkEmbed("✅ Successfully Left"));
await player.leave();
player.destroy();
}
+38 -13
View File
@@ -40,13 +40,13 @@ export class Dashboard {
case "server": {
try {
const guild = this.remix.client.guilds.cache.get(data.key);
const guild = this.remix.client.guilds.get(data.key);
if (!guild) return { error: "Server not found" };
const member = await guild.members.fetch(data.accessor).catch(() => null);
const server = Dashboard.convertServer(guild);
if (member) {
server.channels = server.channels.filter(c => {
const ch = guild.channels.cache.get(c.id);
const ch = guild.channels.get(c.id);
return ch ? ch.permissionsFor(member)?.has("ViewChannel") : false;
});
}
@@ -216,9 +216,22 @@ export class Dashboard {
static convertChannel(channel) {
const isVoice = channel.isVoiceBased?.() ?? false;
// Collect voice members for voice channels
const voiceParticipants = isVoice
? [...(channel.members?.values() ?? [])].map(m => Dashboard.convertUser(m.user))
: [];
let voiceParticipants = [];
if (isVoice) {
const guild = channel?.guild ?? channel?.client?.guilds?.get(channel?.guildId);
if (guild?.voice_states) {
const vs = Array.isArray(guild.voice_states) ? guild.voice_states :
typeof guild.voice_states.values === "function" ? [...guild.voice_states.values()] : Object.values(guild.voice_states);
for (const state of vs) {
const scId = String(state?.channelId ?? state?.channel_id ?? "").replace(/\D/g, "");
const chId = String(channel?.id ?? "").replace(/\D/g, "");
if (scId === chId) {
const user = guild.members?.get?.(state?.userId ?? state?.user_id)?.user;
if (user && !user.bot) voiceParticipants.push(Dashboard.convertUser(user));
}
}
}
}
return {
name: channel.name,
@@ -237,11 +250,7 @@ export class Dashboard {
* @param {import("discord.js").Guild} guild
*/
static convertServer(guild) {
// Defensively handle guild.channels — @fluxerjs/core may not always
// populate .cache (e.g. during recovery or for partial guild objects),
// or guild.channels itself may be a Map/Collection without a .cache
// wrapper. Fallback to guild.channels directly if .cache is absent.
const channelStore = guild.channels?.cache ?? guild.channels;
const channelStore = guild.channels;
const channelIds = channelStore && typeof channelStore.keys === "function"
? [...channelStore.keys()]
: [];
@@ -265,8 +274,8 @@ export class Dashboard {
*/
static convertPlayer(player) {
const channelId = player._channelId;
const channel = channelId ? player.client?.channels?.cache?.get(channelId) : null;
const guild = channel?.guild ?? (player._guildId ? player.client?.guilds?.cache?.get(player._guildId) : null);
const channel = channelId ? player.client?.channels?.get(channelId) : null;
const guild = channel?.guild ?? (player._guildId ? player.client?.guilds?.get(player._guildId) : null);
return {
loop: (player.queue.loop ? 1 : 0) + (player.queue.songLoop ? 2 : 0),
@@ -276,7 +285,23 @@ export class Dashboard {
current: Dashboard.convertVideo(player.queue.current),
data: (player.queue.data ?? []).map(v => Dashboard.convertVideo(v))
},
users: channel?.members ? [...channel.members.values()].map(m => m.id) : [],
users: (() => {
if (!channel) return [];
const g = channel?.guild ?? channel?.client?.guilds?.get(channel?.guildId);
if (!g?.voice_states) return [];
const vs = Array.isArray(g.voice_states) ? g.voice_states :
typeof g.voice_states.values === "function" ? [...g.voice_states.values()] : Object.values(g.voice_states);
const ids = [];
for (const state of vs) {
const scId = String(state?.channelId ?? state?.channel_id ?? "").replace(/\D/g, "");
const chId = String(channel?.id ?? "").replace(/\D/g, "");
if (scId === chId) {
const memberId = String(state?.userId ?? state?.user_id ?? "");
if (memberId) ids.push(memberId);
}
}
return ids;
})(),
channel: channel ? Dashboard.convertChannel(channel) : null,
server: guild ? Dashboard.convertServer(guild) : null,
};