mirror of
https://github.com/musix-org/musix-oss
synced 2024-12-23 06:43:17 +00:00
additional error logging and debugging.
This commit is contained in:
parent
70316495f5
commit
2d7752d2cf
10
index.js
10
index.js
@ -7,7 +7,9 @@ if (config.devMode) {
|
|||||||
config.shards = 1;
|
config.shards = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { ShardingManager } = require("discord.js");
|
const {
|
||||||
|
ShardingManager
|
||||||
|
} = require("discord.js");
|
||||||
const manager = new ShardingManager("./src/bot.js", {
|
const manager = new ShardingManager("./src/bot.js", {
|
||||||
token: config.token,
|
token: config.token,
|
||||||
respawn: config.respawn,
|
respawn: config.respawn,
|
||||||
@ -28,3 +30,9 @@ console.log = function (arg) {
|
|||||||
oldConsole.log(arg);
|
oldConsole.log(arg);
|
||||||
if (!config.devMode) webhookClient.send(arg);
|
if (!config.devMode) webhookClient.send(arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
oldConsole.error = console.error;
|
||||||
|
console.error = function (arg) {
|
||||||
|
oldConsole.error(arg);
|
||||||
|
if (!client.config.devMode) webhookClient.send(arg);
|
||||||
|
};
|
@ -9,3 +9,9 @@ console.log = function (arg) {
|
|||||||
oldConsole.log(arg);
|
oldConsole.log(arg);
|
||||||
if (!client.config.devMode) webhookClient.send(arg);
|
if (!client.config.devMode) webhookClient.send(arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
oldConsole.error = console.error;
|
||||||
|
console.error = function (arg) {
|
||||||
|
oldConsole.error(arg);
|
||||||
|
if (!client.config.devMode) webhookClient.send(arg);
|
||||||
|
};
|
@ -17,7 +17,7 @@ module.exports = {
|
|||||||
msg.channel.send(`${client.messages.joined} ${voiceChannel.name}!`);
|
msg.channel.send(`${client.messages.joined} ${voiceChannel.name}!`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.queue.delete(msg.guild.id);
|
client.queue.delete(msg.guild.id);
|
||||||
client.users.cache.get(client.config.devId).send(client.messages.errorConnecting + error);
|
console.log(error);
|
||||||
return msg.channel.send(client.messages.error);
|
return msg.channel.send(client.messages.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,15 +68,8 @@ module.exports = {
|
|||||||
option.execute(msg, args, client);
|
option.execute(msg, args, client);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
msg.reply(client.messages.errorExeOpt);
|
msg.reply(client.messages.errorExeOpt);
|
||||||
const embed = new Discord.MessageEmbed()
|
console.log(error.toString());
|
||||||
.setTitle(`Musix ${error.toString()}`)
|
console.log(error.stack.replace(/at /g, "**at **"));
|
||||||
.setDescription(error.stack.replace(/at /g, "**at **"))
|
|
||||||
.setColor(client.config.embedColor);
|
|
||||||
client
|
|
||||||
.fetchUser(client.config.devId)
|
|
||||||
.then((user) => user.send(embed))
|
|
||||||
.catch(console.error);
|
|
||||||
client.users.cache.get(client.config.devId).send(embed);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return msg.channel.send(embed);
|
return msg.channel.send(embed);
|
||||||
|
@ -16,7 +16,9 @@ module.exports = {
|
|||||||
name: 'DJ',
|
name: 'DJ',
|
||||||
})
|
})
|
||||||
.then(role => client.global.db.guilds[msg.guild.id].djrole = role.id)
|
.then(role => client.global.db.guilds[msg.guild.id].djrole = role.id)
|
||||||
.catch(console.error)
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
})
|
||||||
client.global.db.guilds[msg.guild.id].dj = true;
|
client.global.db.guilds[msg.guild.id].dj = true;
|
||||||
msg.channel.send(client.messages.djRoleCreated);
|
msg.channel.send(client.messages.djRoleCreated);
|
||||||
}
|
}
|
||||||
|
33
src/events/clientEvents/handler.js
Normal file
33
src/events/clientEvents/handler.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
module.exports = function (client) {
|
||||||
|
const Discord = require('discord.js');
|
||||||
|
client.on('ready', () => {
|
||||||
|
require(`./ready.js`).execute(client, Discord);
|
||||||
|
}).on('message', (msg) => {
|
||||||
|
require(`./msg.js`).execute(client, msg, Discord);
|
||||||
|
}).on('guildCreate', (guild) => {
|
||||||
|
require(`./guildCreate.js`).execute(client, guild);
|
||||||
|
}).on('voiceStateUpdate', (oldState, newState) => {
|
||||||
|
require(`./voiceStateUpdate.js`).execute(client, oldState, newState);
|
||||||
|
}).on('error', (error) => {
|
||||||
|
console.log(error);
|
||||||
|
}).on('debug', (info) => {
|
||||||
|
if (client.config.devMode) console.log(info);
|
||||||
|
}).on('invalidated', () => {
|
||||||
|
console.log("Client session invalidated! Exiting the process!")
|
||||||
|
process.exit(1);
|
||||||
|
}).on('rateLimit', (rateLimitInfo) => {
|
||||||
|
|
||||||
|
}).on('shardDisconnect', (event, id) => {
|
||||||
|
console.log(`Shard ${id} disconnected event ${event}`);
|
||||||
|
}).on('shardError', (error, shardId) => {
|
||||||
|
console.log(`Shard ${shardId} error ${error}`);
|
||||||
|
}).on('shardReady', (id, unavailableGuilds) => {
|
||||||
|
console.log(`Shard ${id} ready. Unavailable guilds: ${unavailableGuilds || 0}`);
|
||||||
|
}).on('shardReconnecting', (id) => {
|
||||||
|
console.log(`shard ${id} reconnecting.`);
|
||||||
|
}).on('shardResume', (id, replayedEvents) => {
|
||||||
|
console.log(`shard ${id} resume events ${replayedEvents}`);
|
||||||
|
}).on("warn", (info) => {
|
||||||
|
console.log(`Warn! info: ${info}`);
|
||||||
|
});
|
||||||
|
}
|
21
src/events/connectionEvents/handler.js
Normal file
21
src/events/connectionEvents/handler.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
module.exports = function (client, connection) {
|
||||||
|
connection.on("authenticated", () => {
|
||||||
|
if (client.config.devMode) console.log("Voice connection initiated.");
|
||||||
|
}).on("debug", (message) => {
|
||||||
|
if (client.config.devMode) console.log(message);
|
||||||
|
}).on("disconnect", () => {
|
||||||
|
if (client.config.devMode) console.log("Voice connection disconnected.");
|
||||||
|
}).on("error", (error) => {
|
||||||
|
console.log(error);
|
||||||
|
}).on("failed", (error) => {
|
||||||
|
if (client.config.devMode) console.log(error);
|
||||||
|
}).on("newSession", () => {
|
||||||
|
if (client.config.devMode) console.log("New voice session id received!");
|
||||||
|
}).on("ready", () => {
|
||||||
|
if (client.config.devMode) console.log("Voice connection ready.");
|
||||||
|
}).on("reconnecting", () => {
|
||||||
|
if (client.config.devMode) console.log("Voice connection reconnecting.");
|
||||||
|
}).on("warn", (warning) => {
|
||||||
|
console.log(`Voice connection warning: ${warning}`);
|
||||||
|
})
|
||||||
|
}
|
@ -1,12 +1,11 @@
|
|||||||
module.exports = async function (client, error, guild) {
|
module.exports = async function (client, error, guild) {
|
||||||
const queue = client.queue.get(guild.id);
|
const queue = client.queue.get(guild.id);
|
||||||
console.error(error);
|
console.log(error);
|
||||||
/*if (error = "Error: input stream: This video contains content from WMG, who has blocked it on copyright grounds.") {
|
/*if (error = "Error: input stream: This video contains content from WMG, who has blocked it on copyright grounds.") {
|
||||||
queue.endReason = "skip";
|
queue.endReason = "skip";
|
||||||
queue.connection.dispatcher.end();
|
queue.connection.dispatcher.end();
|
||||||
return queue.textChannel.send(client.messages.songBlockedWMG);
|
return queue.textChannel.send(client.messages.songBlockedWMG);
|
||||||
}*/
|
}*/
|
||||||
client.users.cache.get(client.config.devId).send(client.messages.dispatcherError + error);
|
|
||||||
queue.voiceChannel.leave();
|
queue.voiceChannel.leave();
|
||||||
client.queue.delete(guild.id);
|
client.queue.delete(guild.id);
|
||||||
return queue.textChannel.send(client.messages.errorDispatcher + `\`${error}\``);
|
return queue.textChannel.send(client.messages.errorDispatcher + `\`${error}\``);
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
module.exports = async function (client, reason, guild) {
|
module.exports = {
|
||||||
|
async execute(client, guild) {
|
||||||
const queue = client.queue.get(guild.id);
|
const queue = client.queue.get(guild.id);
|
||||||
queue.playing = false;
|
queue.playing = false;
|
||||||
if (reason === "seek") {
|
if (queue.endReason === "seek") {
|
||||||
return (queue.playing = true);
|
return (queue.playing = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,10 +14,11 @@ module.exports = async function (client, reason, guild) {
|
|||||||
queue.time = 0;
|
queue.time = 0;
|
||||||
queue.votes = 0;
|
queue.votes = 0;
|
||||||
queue.voters = [];
|
queue.voters = [];
|
||||||
if (reason !== "replay") {
|
if (queue.endReason !== "replay") {
|
||||||
if (reason === "previous") queue.songs.unshift(queue.prevSongs.pop())
|
if (queue.endReason === "previous") queue.songs.unshift(queue.prevSongs.pop())
|
||||||
if (reason !== "previous") queue.prevSongs.push(queue.songs.shift());
|
if (queue.endReason !== "previous") queue.prevSongs.push(queue.songs.shift());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.funcs.play(guild, queue.songs[0], client, 0, true);
|
client.funcs.play(guild, queue.songs[0], client, 0, true);
|
||||||
|
},
|
||||||
};
|
};
|
16
src/events/dispatcherEvents/handler.js
Normal file
16
src/events/dispatcherEvents/handler.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
module.exports = function (client, dispatcher, queue, guild) {
|
||||||
|
dispatcher.on("finish", () => {
|
||||||
|
if (client.config.devMode) console.log("Dispatcher finish.");
|
||||||
|
require("./finish").execute(client, guild);
|
||||||
|
})
|
||||||
|
.on("start", () => {
|
||||||
|
if (client.config.devMode) console.log("Dispatcher start.");
|
||||||
|
queue.endReason = null;
|
||||||
|
dispatcher.player.streamingData.pausedTime = 0;
|
||||||
|
})
|
||||||
|
.on("error", (error) => {
|
||||||
|
require("./error").execute(client, error, guild);
|
||||||
|
}).on("debug", (info) => {
|
||||||
|
if (client.config.devMode) console.log(info);
|
||||||
|
})
|
||||||
|
}
|
@ -1,19 +0,0 @@
|
|||||||
module.exports = function (client) {
|
|
||||||
const Discord = require('discord.js');
|
|
||||||
const events = './clientEvents/';
|
|
||||||
client.on('ready', () => {
|
|
||||||
require(`${events}ready.js`).execute(client, Discord);
|
|
||||||
});
|
|
||||||
client.on('message', (msg) => {
|
|
||||||
require(`${events}msg.js`).execute(client, msg, Discord);
|
|
||||||
});
|
|
||||||
client.on('guildCreate', (guild) => {
|
|
||||||
require(`${events}guildCreate.js`).execute(client, guild);
|
|
||||||
});
|
|
||||||
client.on('voiceStateUpdate', (oldState, newState) => {
|
|
||||||
require(`${events}voiceStateUpdate.js`).execute(client, oldState, newState);
|
|
||||||
});
|
|
||||||
client.on('error', (error) => {
|
|
||||||
client.channels.fetch(client.config.debug_channel).send(`Error: ${error} on shard: ${client.shard}`);
|
|
||||||
});
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ const admin = require("firebase-admin");
|
|||||||
const serviceAccount = require("./config/serviceAccount.json");
|
const serviceAccount = require("./config/serviceAccount.json");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const events = require("../events/events.js");
|
|
||||||
|
|
||||||
const myIntents = new Intents();
|
const myIntents = new Intents();
|
||||||
myIntents.add(
|
myIntents.add(
|
||||||
@ -39,8 +38,6 @@ module.exports = class extends Client {
|
|||||||
this.messages = require("./config/messages.js");
|
this.messages = require("./config/messages.js");
|
||||||
this.db = admin.firestore();
|
this.db = admin.firestore();
|
||||||
this.db.FieldValue = require("firebase-admin").firestore.FieldValue;
|
this.db.FieldValue = require("firebase-admin").firestore.FieldValue;
|
||||||
this.dispatcher.finish = require("../events/dispatcherEvents/finish.js");
|
|
||||||
this.dispatcher.error = require("../events/dispatcherEvents/error.js");
|
|
||||||
this.global = {
|
this.global = {
|
||||||
db: {
|
db: {
|
||||||
guilds: {},
|
guilds: {},
|
||||||
@ -71,7 +68,7 @@ module.exports = class extends Client {
|
|||||||
this.config.token = this.config.devToken;
|
this.config.token = this.config.devToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
events(this);
|
require("../events/clientEvents/handler.js")(this);
|
||||||
|
|
||||||
this.login(this.config.token).catch((err) =>
|
this.login(this.config.token).catch((err) =>
|
||||||
console.log("Failed to login: " + err)
|
console.log("Failed to login: " + err)
|
||||||
|
@ -24,7 +24,7 @@ module.exports = {
|
|||||||
embedColor: "#b50002",
|
embedColor: "#b50002",
|
||||||
invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
|
invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
|
||||||
supportServer: "https://discord.gg/rvHuJtB",
|
supportServer: "https://discord.gg/rvHuJtB",
|
||||||
devMode: false,
|
devMode: true,
|
||||||
api: false,
|
api: false,
|
||||||
saveDB: true,
|
saveDB: true,
|
||||||
respawn: true,
|
respawn: true,
|
||||||
|
@ -13,16 +13,8 @@ module.exports = function (msg, args, client, Discord, command) {
|
|||||||
command.uses++;
|
command.uses++;
|
||||||
command.execute(msg, args, client, Discord, command);
|
command.execute(msg, args, client, Discord, command);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const date = new Date();
|
|
||||||
msg.reply(client.messages.errorExe);
|
msg.reply(client.messages.errorExe);
|
||||||
const embed = new Discord.MessageEmbed()
|
console.log(error.toString());
|
||||||
.setTitle(`Musix ${error.toString()}`)
|
console.log(error.stack.replace(/at /g, "**at **"));
|
||||||
.setDescription(error.stack.replace(/at /g, "**at **"))
|
|
||||||
.setFooter(
|
|
||||||
`guild: ${msg.guild.id} (${msg.guild.name}), user: ${msg.member.id} (${msg.member.displayName}), channel: ${msg.channel.id} (${msg.channel.name}), date: ${date}, Shard: ${client.shard.ids}`
|
|
||||||
)
|
|
||||||
.setColor("#b50002");
|
|
||||||
client.users.cache.get(client.config.devId).send(embed);
|
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -4,6 +4,6 @@ module.exports = async function (client) {
|
|||||||
await client.channels.fetch(client.config.secondary_test_channel)
|
await client.channels.fetch(client.config.secondary_test_channel)
|
||||||
.then(x => x.join());
|
.then(x => x.join());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.users.cache.get(client.config.devId).send(client.messages.errorDetected + error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -57,12 +57,11 @@ module.exports = async function (
|
|||||||
try {
|
try {
|
||||||
const connection = await voiceChannel.join();
|
const connection = await voiceChannel.join();
|
||||||
construct.connection = connection;
|
construct.connection = connection;
|
||||||
|
require("../../events/connectionEvents/handler")(client, connection);
|
||||||
client.funcs.play(msg.guild, construct.songs[0], client, 0, true);
|
client.funcs.play(msg.guild, construct.songs[0], client, 0, true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
client.queue.delete(msg.guild.id);
|
client.queue.delete(msg.guild.id);
|
||||||
client.users.cache
|
console.log(error);
|
||||||
.get(client.config.devId)
|
|
||||||
.send(client.messages.errorConnecting + error);
|
|
||||||
return msg.channel.send(client.messages.error + error);
|
return msg.channel.send(client.messages.error + error);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -30,7 +30,7 @@ module.exports = async function (guild, song, client, seek, play) {
|
|||||||
if (song.type === "ytdl")
|
if (song.type === "ytdl")
|
||||||
input = ytdl(song.url, streamConfig.ytdlOptions)
|
input = ytdl(song.url, streamConfig.ytdlOptions)
|
||||||
//.on('info', (info, format) => console.log(format))
|
//.on('info', (info, format) => console.log(format))
|
||||||
.on("error", (err) => console.log(err));
|
.on("error", (error) => console.log(error));
|
||||||
|
|
||||||
const ffmpegArgs = [
|
const ffmpegArgs = [
|
||||||
"-analyzeduration",
|
"-analyzeduration",
|
||||||
@ -65,19 +65,9 @@ module.exports = async function (guild, song, client, seek, play) {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
const dispatcher = queue.connection
|
const dispatcher = queue.connection.play(stream, streamConfig.options)
|
||||||
.play(stream, streamConfig.options)
|
|
||||||
.on("finish", () => {
|
|
||||||
client.dispatcher.finish(client, queue.endReason, guild);
|
|
||||||
})
|
|
||||||
.on("start", () => {
|
|
||||||
queue.endReason = null;
|
|
||||||
dispatcher.player.streamingData.pausedTime = 0;
|
|
||||||
})
|
|
||||||
.on("error", (error) => {
|
|
||||||
client.dispatcher.error(client, error, guild);
|
|
||||||
});
|
|
||||||
dispatcher.setVolume(queue.volume / 100);
|
dispatcher.setVolume(queue.volume / 100);
|
||||||
|
require("../../events/dispatcherEvents/handler")(client, dispatcher, queue, guild);
|
||||||
if ((client.global.db.guilds[guild.id].startPlaying && play) || play) {
|
if ((client.global.db.guilds[guild.id].startPlaying && play) || play) {
|
||||||
if (song.type !== "ytdl") return;
|
if (song.type !== "ytdl") return;
|
||||||
const embed = new Discord.MessageEmbed()
|
const embed = new Discord.MessageEmbed()
|
||||||
|
@ -2,7 +2,7 @@ module.exports = function (a) {
|
|||||||
for (let i = a.length - 1; i > 1; i--) {
|
for (let i = a.length - 1; i > 1; i--) {
|
||||||
const j = Math.floor(Math.random() * (i + 1));
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
if (i === 0 || j === 0) {
|
if (i === 0 || j === 0) {
|
||||||
console.log(`J or I is 0. I: ${i} J: ${j}`);
|
// J or I is 0. It works like this so hands off!
|
||||||
} else {
|
} else {
|
||||||
[a[i], a[j]] = [a[j], a[i]];
|
[a[i], a[j]] = [a[j], a[i]];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user