Skip to content

Commit 2bd848d

Browse files
committed
add new /botleave command
1 parent 9fd4d7e commit 2bd848d

File tree

2 files changed

+124
-78
lines changed

2 files changed

+124
-78
lines changed

packages/client-discord/src/index.ts

+47-1
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,24 @@ export class DiscordClient extends EventEmitter {
135135
name: "leavechannel",
136136
description: "Leave the current voice channel",
137137
},
138+
{
139+
name: "botleave",
140+
description: "Bot owner command to leave server",
141+
},
138142
];
139143

140144
try {
145+
// Add debug logging
146+
elizaLogger.debug("Attempting to register commands:", commands);
147+
148+
// Register globally
141149
await this.client.application?.commands.set(commands);
142-
elizaLogger.success("Slash commands registered");
150+
151+
// Log success with more details
152+
elizaLogger.success("Slash commands registered successfully", {
153+
commandCount: commands.length,
154+
commandNames: commands.map((c) => c.name),
155+
});
143156
} catch (error) {
144157
console.error("Error registering slash commands:", error);
145158
}
@@ -372,6 +385,39 @@ export class DiscordClient extends EventEmitter {
372385
case "leavechannel":
373386
await this.voiceManager.handleLeaveChannelCommand(interaction);
374387
break;
388+
case "botleave":
389+
// Check if command user is bot owner
390+
const BOT_OWNER_ID = this.runtime.getSetting(
391+
"DISCORD_BOT_OWNER_ID"
392+
);
393+
394+
// Add debug logging
395+
elizaLogger.debug("Bot leave command attempted", {
396+
commandUserId: interaction.user.id,
397+
expectedOwnerId: BOT_OWNER_ID,
398+
userName: interaction.user.username,
399+
});
400+
401+
if (interaction.user.id !== BOT_OWNER_ID) {
402+
await interaction.reply({
403+
content: "Only the bot owner can use this command.",
404+
ephemeral: true,
405+
});
406+
return;
407+
}
408+
try {
409+
await interaction.reply({
410+
content: "Leaving server as requested by bot owner",
411+
});
412+
await interaction.guild.leave();
413+
} catch (error) {
414+
elizaLogger.error("Error leaving server:", error);
415+
await interaction.reply({
416+
content: "Failed to leave the server.",
417+
ephemeral: true,
418+
});
419+
}
420+
break;
375421
}
376422
}
377423

0 commit comments

Comments
 (0)