From 7c9f22cd341d83a2af5904eef6d067bb0a34ec43 Mon Sep 17 00:00:00 2001 From: Essem Date: Tue, 4 Oct 2022 13:23:23 -0500 Subject: [PATCH] Fix interaction response object issue, fix soundplayer voice state detection --- commands/music/play.js | 4 ++-- events/interactionCreate.js | 30 ++++++++++++++++-------------- utils/soundplayer.js | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/commands/music/play.js b/commands/music/play.js index 43c341e..020548e 100644 --- a/commands/music/play.js +++ b/commands/music/play.js @@ -19,10 +19,10 @@ class PlayCommand extends MusicCommand { } try { const url = new URL(query); - return await play(this.client, url, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true); + return play(this.client, url, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true); } catch { const search = prefixes.some(v => query.startsWith(v)) ? query : !query && attachment ? attachment.url : `ytsearch:${query}`; - return await play(this.client, search, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true); + return play(this.client, search, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true); } } diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 1c18e8f..4302007 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -31,23 +31,25 @@ export default async (client, interaction) => { content: result, flags: commandClass.success ? 0 : 64 }); - } else if (typeof result === "object" && result.embeds) { - await interaction[replyMethod](Object.assign(result, { - flags: result.flags ?? (commandClass.success ? 0 : 64) - })); - } else if (typeof result === "object" && result.contents) { - const fileSize = 8388119; - if (result.contents.length > fileSize) { - if (process.env.TEMPDIR && process.env.TEMPDIR !== "") { - await upload(client, result, interaction, true); + } else if (typeof result === "object") { + if (result.contents && result.name) { + const fileSize = 8388119; + if (result.contents.length > fileSize) { + if (process.env.TEMPDIR && process.env.TEMPDIR !== "") { + await upload(client, result, interaction, true); + } else { + await interaction[replyMethod]({ + content: "The resulting image was more than 8MB in size, so I can't upload it.", + flags: 64 + }); + } } else { - await interaction[replyMethod]({ - content: "The resulting image was more than 8MB in size, so I can't upload it.", - flags: 64 - }); + await interaction[replyMethod](result.text ? result.text : { files: [result] }); } } else { - await interaction[replyMethod](result.text ? result.text : { files: [result] }); + await interaction[replyMethod](Object.assign({ + flags: result.flags ?? (commandClass.success ? 0 : 64) + }, result)); } } } catch (error) { diff --git a/utils/soundplayer.js b/utils/soundplayer.js index b0d6628..0d54248 100644 --- a/utils/soundplayer.js +++ b/utils/soundplayer.js @@ -61,7 +61,7 @@ export function reload() { export async function play(client, sound, options, music = false) { if (!manager) return { content: "The sound commands are still starting up!", flags: 64 }; if (!options.channel.guild) return { content: "This command only works in servers!", flags: 64 }; - if (!options.member.voiceState.channelID) return { content: "You need to be in a voice channel first!", flags: 64 }; + if (!options.member.voiceState) return { content: "You need to be in a voice channel first!", flags: 64 }; if (!options.channel.guild.permissionsOf(client.user.id.toString()).has("CONNECT")) return { content: "I can't join this voice channel!", flags: 64 }; const voiceChannel = options.channel.guild.channels.get(options.member.voiceState.channelID); if (!voiceChannel.permissionsOf(client.user.id.toString()).has("CONNECT")) return { content: "I don't have permission to join this voice channel!", flags: 64 };