diff --git a/examples/basic/basic-example.ts b/examples/basic/basic-example.ts index 3ad7f6c7..eec6ba8a 100644 --- a/examples/basic/basic-example.ts +++ b/examples/basic/basic-example.ts @@ -97,7 +97,7 @@ async function connectToChannel(channel: VoiceChannel) { */ const client = new Client({ - ws: { intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] }, + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES], }); void client.login('token here'); diff --git a/examples/music-bot/config.example.json b/examples/music-bot/config.example.json new file mode 100644 index 00000000..a3ce7af7 --- /dev/null +++ b/examples/music-bot/config.example.json @@ -0,0 +1,4 @@ +{ + "token": "Your Discord bot token here", + "deployment_guild_id": "Private guild ID for deploy command" +} diff --git a/examples/music-bot/src/bot.ts b/examples/music-bot/src/bot.ts index 115e20f9..81e42f73 100644 --- a/examples/music-bot/src/bot.ts +++ b/examples/music-bot/src/bot.ts @@ -1,4 +1,4 @@ -import Discord, { Interaction, GuildMember, Snowflake } from 'discord.js'; +import { Client, Interaction, GuildMember, Snowflake } from 'discord.js'; import { AudioPlayerStatus, AudioResource, @@ -10,19 +10,17 @@ import { Track } from './music/track'; import { MusicSubscription } from './music/subscription'; // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -const { token } = require('../auth.json'); +const { token, deployment_guild_id } = require('../config.json'); -const client = new Discord.Client({ intents: ['GUILD_VOICE_STATES', 'GUILD_MESSAGES', 'GUILDS'] }); +const client = new Client({ intents: ['GUILD_VOICE_STATES', 'GUILDS'] }); -client.on('ready', () => console.log('Ready!')); +client.on('ready', async () => { + console.log('Ready!'); -// This contains the setup code for creating slash commands in a guild. The owner of the bot can send "!deploy" to create them. -client.on('messageCreate', async (message) => { - if (!message.guild) return; - if (!client.application?.owner) await client.application?.fetch(); - - if (message.content.toLowerCase() === '!deploy' && message.author.id === client.application?.owner?.id) { - await message.guild.commands.set([ + const app = await client.application?.fetch(); + const devGuild = await client.guilds.fetch(deployment_guild_id).catch(() => null); + if (app && devGuild) { + await devGuild.commands.set([ { name: 'play', description: 'Plays a song', @@ -56,8 +54,7 @@ client.on('messageCreate', async (message) => { description: 'Leave the voice channel', }, ]); - - await message.reply('Deployed!'); + console.log('Deployed slash commands!'); } }); @@ -72,7 +69,7 @@ client.on('interactionCreate', async (interaction: Interaction) => { let subscription = subscriptions.get(interaction.guildId); if (interaction.commandName === 'play') { - await interaction.defer(); + await interaction.deferReply(); // Extract the video URL from the command const url = interaction.options.get('song')!.value! as string; diff --git a/examples/recorder/README.md b/examples/recorder/README.md index 397542d5..fc0e6f7e 100644 --- a/examples/recorder/README.md +++ b/examples/recorder/README.md @@ -14,8 +14,8 @@ $ npm run build $ cd examples/recorder $ npm install -# Set a bot token (see auth.example.json) -$ cp auth.example.json auth.json +# Set a bot token & deployment guild id (see config.example.json) +$ cp config.example.json config.json $ nano auth.json # Start the bot! diff --git a/examples/recorder/auth.example.json b/examples/recorder/auth.example.json deleted file mode 100644 index 34e3fca0..00000000 --- a/examples/recorder/auth.example.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "token": "Your Discord bot token here" -} diff --git a/examples/music-bot/auth.example.json b/examples/recorder/config.example.json similarity index 100% rename from examples/music-bot/auth.example.json rename to examples/recorder/config.example.json diff --git a/examples/recorder/src/bot.ts b/examples/recorder/src/bot.ts index 498dacaf..33b7b467 100644 --- a/examples/recorder/src/bot.ts +++ b/examples/recorder/src/bot.ts @@ -1,22 +1,21 @@ -import Discord, { Interaction } from 'discord.js'; +import { Client, Interaction } from 'discord.js'; import { getVoiceConnection } from '@discordjs/voice'; import { deploy } from './deploy'; import { interactionHandlers } from './interactions'; // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -const { token } = require('../auth.json'); +const { token, deployment_guild_id } = require('../config.json'); -const client = new Discord.Client({ intents: ['GUILD_VOICE_STATES', 'GUILD_MESSAGES', 'GUILDS'] }); +const client = new Client({ intents: ['GUILD_VOICE_STATES', 'GUILDS'] }); -client.on('ready', () => console.log('Ready!')); +client.on('ready', async () => { + console.log('Ready!') -client.on('messageCreate', async (message) => { - if (!message.guild) return; - if (!client.application?.owner) await client.application?.fetch(); - - if (message.content.toLowerCase() === '!deploy' && message.author.id === client.application?.owner?.id) { - await deploy(message.guild); - await message.reply('Deployed!'); + const app = await client.application?.fetch(); + const devGuild = await client.guilds.fetch(deployment_guild_id).catch(() => null); + if (app && devGuild) { + await deploy(devGuild); + console.log('Deployed commands!'); } }); diff --git a/src/joinVoiceChannel.ts b/src/joinVoiceChannel.ts index 85de47de..123dc1dd 100644 --- a/src/joinVoiceChannel.ts +++ b/src/joinVoiceChannel.ts @@ -31,7 +31,7 @@ export interface JoinVoiceChannelOptions { */ selfDeaf?: boolean; /** - * Whether to join the channel muted (defaults to true) + * Whether to join the channel muted (defaults to false) */ selfMute?: boolean; /**