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

fix(Interaction): update interaction methods #244

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 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 Discord, { Interaction, GuildMember, Snowflake, Message } from 'discord.js';
import {
AudioPlayerStatus,
AudioResource,
Expand All @@ -17,7 +17,7 @@ const client = new Discord.Client({ intents: ['GUILD_VOICE_STATES', 'GUILD_MESSA
client.on('ready', () => 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) => {
client.on('messageCreate', async (message: Message) => {
if (!message.guild) return;
if (!client.application?.owner) await client.application?.fetch();

Expand Down Expand Up @@ -72,9 +72,9 @@ 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;
const url = interaction.options.getString('song') as string;
Copy link

@imranbarbhuiya imranbarbhuiya Dec 30, 2021

Choose a reason for hiding this comment

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

You can just add true as the 2nd parameter and it's type will be string

- const url = interaction.options.getString('song') as string;

+ const url = interaction.options.getString('song', true);


// If a connection to the guild doesn't already exist and the user is in a voice channel, join that channel
// and create a subscription.
Expand Down
12 changes: 3 additions & 9 deletions examples/music-bot/src/music/track.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getInfo } from 'ytdl-core';
import { AudioResource, createAudioResource, demuxProbe } from '@discordjs/voice';
import { raw as ytdl } from 'youtube-dl-exec';
const ytdla = require('ytdl-core')

/**
* This is the data required to create a Track object.
Expand Down Expand Up @@ -46,14 +47,7 @@ export class Track implements TrackData {
public createAudioResource(): Promise<AudioResource<Track>> {
return new Promise((resolve, reject) => {
const process = ytdl(
this.url,
{
o: '-',
q: '',
f: 'bestaudio[ext=webm+acodec=opus+asr=48000]/bestaudio',
r: '100K',
},
{ stdio: ['ignore', 'pipe', 'ignore'] },
this.url
);
if (!process.stdout) {
reject(new Error('No stdout'));
Expand All @@ -68,7 +62,7 @@ export class Track implements TrackData {
process
.once('spawn', () => {
demuxProbe(stream)
.then((probe: { stream: any; type: any; }) => resolve(createAudioResource(probe.stream, { metadata: this, inputType: probe.type })))
.then(async (probe: { stream: any; type: any; }) => resolve(createAudioResource(await ytdla(this.url), { metadata: this, inputType: probe.type })))
.catch(onError);
})
.catch(onError);
Expand Down