fix: prevents youtube bot blocking #171
2 changed files with 14 additions and 4 deletions
|
@ -1,13 +1,24 @@
|
||||||
import { Player, PlayerEvents, useMainPlayer } from "discord-player";
|
import { PlayerEvents, useMainPlayer } from "discord-player";
|
||||||
import { Client } from "discord.js";
|
import { Client } from "discord.js";
|
||||||
import { readdir } from "fs/promises";
|
import { readdir } from "fs/promises";
|
||||||
|
|
||||||
/** Load all the events */
|
/** Load all the events */
|
||||||
export default async (client: Client) => {
|
export default async (client: Client, isDev: boolean) => {
|
||||||
const events_categories = (await readdir(__dirname)).filter(
|
const events_categories = (await readdir(__dirname)).filter(
|
||||||
(element) => !element.endsWith(".js") && !element.endsWith(".ts"),
|
(element) => !element.endsWith(".js") && !element.endsWith(".ts"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const player = useMainPlayer();
|
||||||
|
|
||||||
|
if (isDev) {
|
||||||
|
player.on("debug", async (message) => {
|
||||||
|
console.log(`General player debug event: ${message}`);
|
||||||
|
});
|
||||||
|
player.events.on("debug", async (_, message) => {
|
||||||
|
console.log(`Player debug event: ${message}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
events_categories.forEach(async (event_category) => {
|
events_categories.forEach(async (event_category) => {
|
||||||
// Retrieve events
|
// Retrieve events
|
||||||
const events = await readdir(`${__dirname}/${event_category}`);
|
const events = await readdir(`${__dirname}/${event_category}`);
|
||||||
|
@ -29,7 +40,6 @@ export default async (client: Client) => {
|
||||||
const event_type = event_type_ext.join(".");
|
const event_type = event_type_ext.join(".");
|
||||||
|
|
||||||
if (event_category == "player") {
|
if (event_category == "player") {
|
||||||
const player = useMainPlayer() as Player;
|
|
||||||
if (once) {
|
if (once) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
return player.events.once(event_type as keyof PlayerEvents, (...args: any[]) => {
|
return player.events.once(event_type as keyof PlayerEvents, (...args: any[]) => {
|
||||||
|
|
|
@ -21,7 +21,7 @@ export const run = async (isDev: boolean) => {
|
||||||
|
|
||||||
// Events Discord.JS and Player
|
// Events Discord.JS and Player
|
||||||
const events_name = "Events";
|
const events_name = "Events";
|
||||||
await loadEvents(client)
|
await loadEvents(client, isDev)
|
||||||
.then(() => console.log(logStart(events_name, true)))
|
.then(() => console.log(logStart(events_name, true)))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
Loading…
Reference in a new issue