Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

chore: update examples for v13 #174

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/basic/basic-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions examples/music-bot/config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"token": "Your Discord bot token here",
"deployment_guild_id": "Private guild ID for deploy command"
}
25 changes: 11 additions & 14 deletions examples/music-bot/src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Discord, { Interaction, GuildMember, Snowflake } from 'discord.js';
import { Client, Interaction, GuildMember, Snowflake } from 'discord.js';
import {
AudioPlayerStatus,
AudioResource,
Expand All @@ -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', 'GUILD_MESSAGES', 'GUILDS'] });
Fyko marked this conversation as resolved.
Show resolved Hide resolved

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([
Copy link
Contributor

@iim-ayush iim-ayush Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have some check if the commands are already present in the guild before setting commands again and again at every start of bot.

{
name: 'play',
description: 'Plays a song',
Expand Down Expand Up @@ -56,8 +54,7 @@ client.on('messageCreate', async (message) => {
description: 'Leave the voice channel',
},
]);

await message.reply('Deployed!');
console.log('Deployed slash commands!');
}
});

Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions examples/recorder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
3 changes: 0 additions & 3 deletions examples/recorder/auth.example.json

This file was deleted.

21 changes: 10 additions & 11 deletions examples/recorder/src/bot.ts
Original file line number Diff line number Diff line change
@@ -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!');
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/joinVoiceChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down