Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some issues with sharding and wrong quoting #247

Open
wants to merge 3 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
53 changes: 38 additions & 15 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
DISCORD_TOKEN=
MONGO_TOKEN=
GIPHY_TOKEN=
WEBHOOK_ID=
WEBHOOK_TOKEN=
DISCORD_ID=

# Not neccessary variables
# Wondering how to get these? Check out https://github.com/CorwinDev/Discord-Bot#requirements
# Required Environment Variables

# Discord bot token (REQUIRED)
DISCORD_TOKEN=your_discord_token_here

# MongoDB URI or Token (REQUIRED)
MONGO_TOKEN=your_mongo_uri_here

# GIPHY API token for GIF functionality (REQUIRED)
GIPHY_TOKEN=your_giphy_token_here

# Discord Webhook ID and Token (REQUIRED for bot logs)
WEBHOOK_ID=your_webhook_id_here
WEBHOOK_TOKEN=your_webhook_token_here

# Discord User ID (REQUIRED for certain bot features)
DISCORD_ID=your_discord_user_id_here


# Optional Variables

# Discord bot status (Optional)
DISCORD_STATUS="Listening to meself, I'm a stupid bot, https://github.com/corwindev/discord-bot"
RADIO=
TOPGG_TOKEN=
SPOTIFY_CLIENT_ID=
SPOTIFY_CLIENT_SECRET=

# URL to radio stream (Optional)
RADIO=your_radio_url_here

# Top.gg API token for bot statistics (Optional)
TOPGG_TOKEN=your_topgg_token_here

# Spotify API credentials (Optional, for music bot functionality)
SPOTIFY_CLIENT_ID=your_spotify_client_id_here
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret_here

# Lavalink configuration for music bot (Optional)
LAVALINK_HOST=lava.link
LAVALINK_PASSWORD=I'm a secret
LAVALINK_PASSWORD=your_lavalink_password_here
LAVALINK_PORT=80
LAVALINK_SECURE=false
OPENAI=

# OpenAI API token (Optional, for AI integration)
OPENAI=your_openai_token_here
130 changes: 52 additions & 78 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ const AppleMusic = require("erela.js-apple");
// Discord client
const client = new Discord.Client({
allowedMentions: {
parse: [
'users',
'roles'
],
parse: ['users', 'roles'],
repliedUser: true
},
autoReconnect: true,
disabledEvents: [
"TYPING_START"
],
partials: [
Discord.Partials.Channel,
Discord.Partials.GuildMember,
Expand Down Expand Up @@ -49,7 +43,6 @@ const client = new Discord.Client({
restTimeOffset: 0
});


const clientID = process.env.SPOTIFY_CLIENT_ID;
const clientSecret = process.env.SPOTIFY_CLIENT_SECRET;
if (clientID && clientSecret) {
Expand All @@ -66,23 +59,22 @@ if (clientID && clientSecret) {
],
nodes: [
{
host: process.env.LAVALINK_HOST || "lava.link",
port: parseInt(process.env.LAVALINK_PORT) || 80,
password: process.env.LAVALINK_PASSWORD || "CorwinDev",
secure: Boolean(process.env.LAVALINK_SECURE) || false
host: process.env.LAVALINK_HOST || "Your-LavaLink-Here",
port: parseInt(process.env.LAVALINK_PORT) || port,
password: process.env.LAVALINK_PASSWORD || "Your-LavaLink-Password-Here",
secure: Boolean(process.env.LAVALINK_SECURE) || " "true" for ssl enabled and "false" for diabled "
},
{
host: "lavalink.techpoint.world",
port: 80,
password: "techpoint"
host: "Your-LavaLink-Here",
port: port,
password: "Your-LavaLink-Password-Here"
},
],
send(id, payload) {
const guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
},
})

});
} else {
// Lavalink client
client.player = new Manager({
Expand All @@ -93,24 +85,24 @@ if (clientID && clientSecret) {
],
nodes: [
{
host: process.env.LAVALINK_HOST || "lava.link",
port: parseInt(process.env.LAVALINK_PORT) || 80,
password: process.env.LAVALINK_PASSWORD || "CorwinDev",
secure: Boolean(process.env.LAVALINK_SECURE) || false
host: process.env.LAVALINK_HOST || "Your-Other-LavaLink-Here",
port: parseInt(process.env.LAVALINK_PORT) || port,
password: process.env.LAVALINK_PASSWORD || "Your-LavaLink-Password-Here",
secure: Boolean(process.env.LAVALINK_SECURE) || " "true" for ssl enabled and "false" for diabled "
},
],
send(id, payload) {
const guild = client.guilds.cache.get(id);
if (guild) guild.shard.send(payload);
}
})
});
}
const events = fs.readdirSync(`./src/events/music`).filter(files => files.endsWith('.js'));

const events = fs.readdirSync('./src/events/music').filter(file => file.endsWith('.js'));
for (const file of events) {
const event = require(`./events/music/${file}`);
client.player.on(file.split(".")[0], event.bind(null, client)).setMaxListeners(0);
};
}

// Connect to database
require("./database/connect")();
Expand All @@ -120,7 +112,13 @@ client.config = require('./config/bot');
client.changelogs = require('./config/changelogs');
client.emotes = require("./config/emojis.json");
client.webhooks = require("./config/webhooks.json");
const webHooksArray = ['startLogs', 'shardLogs', 'errorLogs', 'dmLogs', 'voiceLogs', 'serverLogs', 'serverLogs2', 'commandLogs', 'consoleLogs', 'warnLogs', 'voiceErrorLogs', 'creditLogs', 'evalLogs', 'interactionLogs'];

const webHooksArray = [
'startLogs', 'shardLogs', 'errorLogs', 'dmLogs', 'voiceLogs', 'serverLogs',
'serverLogs2', 'commandLogs', 'consoleLogs', 'warnLogs', 'voiceErrorLogs',
'creditLogs', 'evalLogs', 'interactionLogs'
];

// Check if .env webhook_id and webhook_token are set
if (process.env.WEBHOOK_ID && process.env.WEBHOOK_TOKEN) {
for (const webhookName of webHooksArray) {
Expand Down Expand Up @@ -156,71 +154,47 @@ client.login(process.env.DISCORD_TOKEN);

process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
if (error) if (error.length > 950) error = error.slice(0, 950) + '... view console for details';
if (error.stack) if (error.stack.length > 950) error.stack = error.stack.slice(0, 950) + '... view console for details';
if(!error.stack) return
if (error && error.length > 950) error = error.slice(0, 950) + '... view console for details';
if (error.stack && error.stack.length > 950) error.stack = error.stack.slice(0, 950) + '... view console for details';
if (!error.stack) return;

const embed = new Discord.EmbedBuilder()
.setTitle(`🚨・Unhandled promise rejection`)
.setTitle('🚨・Unhandled promise rejection')
.addFields([
{
name: "Error",
value: error ? Discord.codeBlock(error) : "No error",
},
{
name: "Stack error",
value: error.stack ? Discord.codeBlock(error.stack) : "No stack error",
}
{ name: "Error", value: error ? Discord.codeBlock(error) : "No error" },
{ name: "Stack error", value: error.stack ? Discord.codeBlock(error.stack) : "No stack error" }
])
.setColor(client.config.colors.normal)
consoleLogs.send({
username: 'Bot Logs',
embeds: [embed],
}).catch(() => {
console.log('Error sending unhandledRejection to webhook')
console.log(error)
})
.setColor(client.config.colors.normal);

consoleLogs.send({ username: 'Bot Logs', embeds: [embed] })
.catch(() => console.log('Error sending unhandledRejection to webhook'));
});

process.on('warning', warn => {
console.warn("Warning:", warn);

const embed = new Discord.EmbedBuilder()
.setTitle(`🚨・New warning found`)
.addFields([
{
name: `Warn`,
value: `\`\`\`${warn}\`\`\``,
},
])
.setColor(client.config.colors.normal)
warnLogs.send({
username: 'Bot Logs',
embeds: [embed],
}).catch(() => {
console.log('Error sending warning to webhook')
console.log(warn)
})
.setTitle('🚨・New warning found')
.addFields([{ name: 'Warn', value: `\`\`\`${warn}\`\`\`` }])
.setColor(client.config.colors.normal);

warnLogs.send({ username: 'Bot Logs', embeds: [embed] })
.catch(() => console.log('Error sending warning to webhook'));
});

client.on(Discord.ShardEvents.Error, error => {
console.log(error)
if (error) if (error.length > 950) error = error.slice(0, 950) + '... view console for details';
if (error.stack) if (error.stack.length > 950) error.stack = error.stack.slice(0, 950) + '... view console for details';
if (!error.stack) return
console.log(error);
if (error && error.length > 950) error = error.slice(0, 950) + '... view console for details';
if (error.stack && error.stack.length > 950) error.stack = error.stack.slice(0, 950) + '... view console for details';
if (!error.stack) return;

const embed = new Discord.EmbedBuilder()
.setTitle(`🚨・A websocket connection encountered an error`)
.setTitle('🚨・A websocket connection encountered an error')
.addFields([
{
name: `Error`,
value: `\`\`\`${error}\`\`\``,
},
{
name: `Stack error`,
value: `\`\`\`${error.stack}\`\`\``,
}
{ name: 'Error', value: `\`\`\`${error}\`\`\`` },
{ name: 'Stack error', value: `\`\`\`${error.stack}\`\`\`` }
])
.setColor(client.config.colors.normal)
consoleLogs.send({
username: 'Bot Logs',
embeds: [embed],
});
.setColor(client.config.colors.normal);

consoleLogs.send({ username: 'Bot Logs', embeds: [embed] });
});
Loading