Added option to disable YouTube support

This commit is contained in:
Essem 2022-10-10 11:53:45 -05:00
parent 006ce416aa
commit ba46701589
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
3 changed files with 6 additions and 2 deletions

View file

@ -28,6 +28,8 @@ PREFIX=&
# Set this to true if you want the bot to stay in voice chats after sound effects and music have stopped
# (you can still make the bot leave using the stop command)
STAYVC=false
# Set this to true to disable music playback from YouTube
YT_DISABLED=false
# Put DBL/top.gg token here
DBL=

View file

@ -1,6 +1,7 @@
import { play } from "../../utils/soundplayer.js";
import MusicCommand from "../../classes/musicCommand.js";
const prefixes = ["ytsearch:", "ytmsearch:", "scsearch:", "spsearch:", "amsearch:"];
const prefixes = ["scsearch:", "spsearch:", "sprec:", "amsearch:", "dzsearch:", "dzisrc:"];
if (process.env.YT_DISABLED !== "true") prefixes.push("ytsearch:", "ytmsearch:");
class PlayCommand extends MusicCommand {
async run() {
@ -21,7 +22,7 @@ class PlayCommand extends MusicCommand {
const url = new URL(query);
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}`;
const search = prefixes.some(v => query.startsWith(v)) ? query : !query && attachment ? attachment.url : (process.env.YT_DISABLED !== "true" ? `ytsearch:${query}` : `dzsearch:${query}`);
return play(this.client, search, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction }, true);
}
}

View file

@ -88,6 +88,7 @@ export async function play(client, sound, options, music = false) {
}
const oldQueue = queues.get(voiceChannel.guildID);
if (!response.tracks || response.tracks.length === 0) return { content: "I couldn't find that song!", flags: 64 };
if (process.env.YT_DISABLED === "true" && response.tracks[0].info.sourceName === "youtube") return "YouTube playback is disabled on this instance.";
if (music) {
const sortedTracks = response.tracks.map((val) => { return val.track; });
const playlistTracks = response.playlistInfo.selectedTrack ? sortedTracks : [sortedTracks[0]];