bot: explain when the bot user hasn't joined the server, with an invite link
This commit is contained in:
1 parent
9313c51b4b
commit
2e04d9efb4
1 file changed
+12
@@ -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.`));
|
||||||
|
|||||||
Reference in new issue
Block a user