fix: replace defer/edit with reply/followup

This commit is contained in:
ethanf 2024-01-16 14:48:57 -06:00
parent 974d01a08f
commit 1c4aff27de

View File

@ -20,16 +20,21 @@ const client = new Client({
client.on("ready", () => { client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`); console.log(`Logged in as ${client.user.tag}!`);
console.log(`Deleting old messages from this bot in command channel: ${COMMAND_CHANNEL_ID}...`); console.log(
`Deleting old messages from this bot in command channel: ${COMMAND_CHANNEL_ID}...`
);
let channel = client.channels.cache.get(COMMAND_CHANNEL_ID); let channel = client.channels.cache.get(COMMAND_CHANNEL_ID);
if (!channel) return console.error("(ready) Can't find command channel"); if (!channel) return console.error("(ready) Can't find command channel");
channel.messages.fetch({ limit: 100 }).then(messages => { channel.messages
messages.forEach(message => { .fetch({ limit: 100 })
.then((messages) => {
messages.forEach((message) => {
if (message.author.id === client.user.id) { if (message.author.id === client.user.id) {
message.delete(); message.delete();
} }
}); });
}).catch(console.error); })
.catch(console.error);
}); });
// send message on error // send message on error
@ -81,7 +86,10 @@ client.on("interactionCreate", async (interaction) => {
}); });
return; return;
} else { } else {
await interaction.deferReply(); await interaction.reply({
content: "checking picking channel...",
ephemeral: true,
});
// set role name // set role name
let roleName = command; let roleName = command;
@ -89,19 +97,18 @@ client.on("interactionCreate", async (interaction) => {
if (command === "engi") roleName = "engineer"; if (command === "engi") roleName = "engineer";
// check each member in picking channel for role // check each member in picking channel for role
let str = "In picking:"; let str = `In picking (${roleName}):`;
for (const member of picking.members.values()) { for (const member of picking.members.values()) {
if (member.roles.cache.find((role) => role.name === roleName)) { if (member.roles.cache.find((role) => role.name === roleName)) {
if (str !== "In picking:") str += ","; if (str !== `In picking (${roleName}):`) str += ",";
str += " " + member.user.globalName; str += " " + member.user.globalName;
} }
} }
if (str === "In picking:") str = "None found ¯\\_(ツ)_/¯"; if (str === `In picking (${roleName}):`)
str = `None found ¯\\_(ツ)_/¯ (${roleName})`;
// respond // respond
return await interaction.editReply({ return await interaction.followUp(str);
content: str,
});
} }
} }
@ -122,7 +129,7 @@ client.on("interactionCreate", async (interaction) => {
command === "end" || command === "end" ||
command === "resetteams" command === "resetteams"
) { ) {
await interaction.deferReply(); await interaction.reply("moving members...");
// get voice channels // get voice channels
const blu = interaction.guild.channels.cache.find( const blu = interaction.guild.channels.cache.find(
@ -146,7 +153,7 @@ client.on("interactionCreate", async (interaction) => {
let members = blu.members.concat(red.members); let members = blu.members.concat(red.members);
if (command !== "resetteams") members = members.concat(addup.members); if (command !== "resetteams") members = members.concat(addup.members);
if (members.size === 0) { if (members.size === 0) {
return await interaction.editReply( return await interaction.followUp(
`found no members in ${ `found no members in ${
command === "resetteams" ? "blu" : "addup, blu," command === "resetteams" ? "blu" : "addup, blu,"
} or red` } or red`
@ -158,26 +165,26 @@ client.on("interactionCreate", async (interaction) => {
eCount = 0; eCount = 0;
members.forEach(async (member) => { members.forEach(async (member) => {
idx++; idx++;
console.log(idx, members.size);
try { try {
await member.voice.setChannel(picking); await member.voice.setChannel(picking);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
eCount++; eCount++;
} finally { }
// respond when done // respond when done
if (idx === members.size) { if (idx === members.size) {
return await interaction.editReply({ return await interaction.followUp(
content: `moved members in ${ `moved members in ${
command === "resetteams" ? "blu" : "addup, blu," command === "resetteams" ? "blu" : "addup, blu,"
} and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`, } and red${eCount > 0 ? ` (error moving ${eCount} members)` : ""}`
}); );
}
} }
}); });
} }
if (command === "fk" || command === "fatkid") { if (command === "fk" || command === "fatkid") {
await interaction.deferReply(); await interaction.reply("moving fatkids...");
// get voice channels // get voice channels
const picking = interaction.guild.channels.cache.find( const picking = interaction.guild.channels.cache.find(
@ -191,15 +198,15 @@ client.on("interactionCreate", async (interaction) => {
const members = picking.members; const members = picking.members;
if (members.size === 0) { if (members.size === 0) {
return await interaction.editReply("found no members in picking"); return await interaction.followUp("found no members in picking");
} }
// get members in voice channel // get members in voice channel
let idx = 0, let idx = 0,
eCount = 0, eCount = 0,
str = ""; str = "";
members.forEach(async (member) => { members.forEach(async (member) => {
idx++; idx++;
console.log(idx, members.size);
try { try {
await member.voice.setChannel(fk); await member.voice.setChannel(fk);
if (str.length > 0) str += ", "; if (str.length > 0) str += ", ";
@ -207,20 +214,14 @@ client.on("interactionCreate", async (interaction) => {
} catch (error) { } catch (error) {
console.error(error); console.error(error);
eCount++; eCount++;
} finally { }
// list members when done
if (idx === members.size) { if (idx === members.size) {
if (eCount > 0) { // list members when done
return await interaction.editReply({ return await interaction.followUp(
content: `fatkids: ${str}`, `fatkids: ${str}${
});
}
return await interaction.editReply({
content: `fatkids: ${str}${
eCount > 0 ? ` (error moving ${eCount} members)` : "" eCount > 0 ? ` (error moving ${eCount} members)` : ""
}`, }`
}); );
}
} }
}); });
} }