bot: explain when the bot user hasn't joined the server, with an invite link

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
4DBugandClaude Opus 5.5 committed 2026-10-27 09:14:38 -05:00
1 parent 75d969e1c5
commit f3c88cff19
1 file changed
+12
+12
View File
@@ -70,7 +70,17 @@ async function adoptReply(ctx, room, interaction, deferred) {
ctx.updater.schedule(room, false); // catch anything that changed while we were posting ctx.updater.schedule(room, false); // catch anything that changed while we were posting
} }
// commands can be installed without the bot user joining the server; then Discord never
// sends it voice states and nothing here can work
function notInGuild(interaction, ctx) {
if (interaction.guild) return false;
const invite = `https://discord.com/oauth2/authorize?client_id=${ctx.cfg.applicationId}&scope=bot%20applications.commands&permissions=84992`;
interaction.reply(ephemeral(`The bot user isn't in this server yet, so it can't see voice channels. Add it with this link: ${invite}`)).catch(() => {});
return true;
}
async function watch(interaction, ctx) { async function watch(interaction, ctx) {
if (notInGuild(interaction, ctx)) return;
const vc = await userVoiceChannel(interaction); const vc = await userVoiceChannel(interaction);
if (!vc) return interaction.reply(ephemeral('Join a voice channel first, then use `/watch` there.')); if (!vc) return interaction.reply(ephemeral('Join a voice channel first, then use `/watch` there.'));
const raw = interaction.options.getString('query', true); const raw = interaction.options.getString('query', true);
@@ -99,6 +109,7 @@ async function roomFor(interaction, ctx) {
} }
async function np(interaction, ctx) { async function np(interaction, ctx) {
if (notInGuild(interaction, ctx)) return;
const room = await roomFor(interaction, ctx); const room = await roomFor(interaction, ctx);
if (!room || !room.state.media) return interaction.reply(ephemeral('Nothing is playing. Use `/watch` in a voice channel.')); if (!room || !room.state.media) return interaction.reply(ephemeral('Nothing is playing. Use `/watch` in a voice channel.'));
await interaction.deferReply(); await interaction.deferReply();
@@ -106,6 +117,7 @@ async function np(interaction, ctx) {
} }
async function stop(interaction, ctx) { async function stop(interaction, ctx) {
if (notInGuild(interaction, ctx)) return;
const room = await roomFor(interaction, ctx); const room = await roomFor(interaction, ctx);
if (!room) return interaction.reply(ephemeral('Nothing is playing.')); if (!room) return interaction.reply(ephemeral('Nothing is playing.'));
if (!ctx.isInVoice(room.id, interaction.user.id)) return interaction.reply(ephemeral(`Join <#${room.id}> to control playback.`)); if (!ctx.isInVoice(room.id, interaction.user.id)) return interaction.reply(ephemeral(`Join <#${room.id}> to control playback.`));