mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 14:38:49 +00:00
feat: Added .env file, and moved some properties from config.json to .env file
This commit is contained in:
1 parent
d96b40e277
commit
cc3fd9569c
9 files changed
+50
-19
No files matched your search
@@ -0,0 +1,5 @@
|
||||
NODE_ENV=development
|
||||
MINIMUM_LOG_LEVEL=debug
|
||||
MINIMUM_LOG_LEVEL_CONSOLE=info
|
||||
DISCORD_BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN
|
||||
DISCORD_CLIENT_ID=YOUR_DISCOR_BOT_CLIENT_ID
|
||||
@@ -1,3 +1,4 @@
|
||||
/node_modules
|
||||
/config.json
|
||||
/.env
|
||||
/app-*.log
|
||||
+5
-6
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"clientId": "Your bot Application ID here.",
|
||||
"token": "Your bot auth token here.",
|
||||
"systemServerGuildIds": ["Server id where system commands can be used", "Another server id where system commands can be used"],
|
||||
"systemServerGuildIds": [
|
||||
"Server id where system commands can be used",
|
||||
"Another server id where system commands can be used"
|
||||
],
|
||||
"embedColors": {
|
||||
"colorSuccess": "#23A55A",
|
||||
"colorWarning": "#F0B232",
|
||||
@@ -28,9 +29,7 @@
|
||||
"leftChar": "▬",
|
||||
"rightChar": "▬"
|
||||
},
|
||||
"minimumLogLevel": "debug",
|
||||
"minimumLogLevelConsole": "info",
|
||||
"filterThreadAmount": "4",
|
||||
"filterThreadAmount": "2",
|
||||
"filterList": [
|
||||
{
|
||||
"label": "Bass boost",
|
||||
|
||||
+10
-5
@@ -1,7 +1,7 @@
|
||||
const fs = require('node:fs');
|
||||
const logger = require('./services/logger.js');
|
||||
const { REST, Routes } = require('discord.js');
|
||||
const { token, clientId } = require('./config.json');
|
||||
require('dotenv').config();
|
||||
|
||||
const commands = [];
|
||||
const commandFiles = fs
|
||||
@@ -13,7 +13,9 @@ for (const file of commandFiles) {
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(token);
|
||||
const rest = new REST({ version: '10' }).setToken(
|
||||
process.env.DISCORD_BOT_TOKEN
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
@@ -27,9 +29,12 @@ const rest = new REST({ version: '10' }).setToken(token);
|
||||
|
||||
logger.info('Started refreshing application (/) bot commands.');
|
||||
|
||||
await rest.put(Routes.applicationCommands(clientId), {
|
||||
body: commands
|
||||
});
|
||||
await rest.put(
|
||||
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID),
|
||||
{
|
||||
body: commands
|
||||
}
|
||||
);
|
||||
|
||||
logger.info('Successfully refreshed application (/) bot commands.');
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
const fs = require('node:fs');
|
||||
const logger = require('./services/logger.js');
|
||||
const { REST, Routes } = require('discord.js');
|
||||
const { token, clientId, systemServerGuildIds } = require('./config.json');
|
||||
const { systemServerGuildIds } = require('./config.json');
|
||||
require('dotenv').config();
|
||||
|
||||
const systemCommands = [];
|
||||
const systemCommandFiles = fs
|
||||
@@ -13,7 +14,7 @@ for (const file of systemCommandFiles) {
|
||||
systemCommands.push(systemCommand.data.toJSON());
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(token);
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
@@ -29,7 +30,7 @@ const rest = new REST({ version: '10' }).setToken(token);
|
||||
|
||||
for (const systemServerGuildId of systemServerGuildIds) {
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, systemServerGuildId),
|
||||
Routes.applicationGuildCommands(process.env.DISCORD_CLIENT_ID, systemServerGuildId),
|
||||
{
|
||||
body: systemCommands
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ const logger = require('./services/logger.js');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { Player, onBeforeCreateStream } = require('discord-player');
|
||||
const { stream } = require('yt-stream');
|
||||
const { token, embedColors } = require('./config.json');
|
||||
const { embedColors } = require('./config.json');
|
||||
require('dotenv').config();
|
||||
|
||||
// Setup required permissions for the bot to work
|
||||
const client = new Discord.Client({
|
||||
@@ -51,6 +52,12 @@ onBeforeCreateStream(async (track) => {
|
||||
return null;
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
player.events.on('debug', (message) => {
|
||||
logger.debug(message);
|
||||
});
|
||||
}
|
||||
|
||||
player.events.on('error', (queue, error) => {
|
||||
// Emitted when the player queue encounters error
|
||||
logger.error(error, 'Player queue error event');
|
||||
@@ -180,4 +187,4 @@ client.on('interactionCreate', async (interaction) => {
|
||||
}
|
||||
});
|
||||
|
||||
client.login(token);
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
||||
Generated
+12
@@ -15,6 +15,7 @@
|
||||
"@discordjs/voice": "^0.16.0",
|
||||
"discord-player": "^6.6.1",
|
||||
"discord.js": "^14.11.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"pino": "^8.14.1",
|
||||
"pino-pretty": "^10.0.1",
|
||||
"yt-stream": "^1.4.8"
|
||||
@@ -660,6 +661,17 @@
|
||||
"url": "https://github.com/fb55/domutils?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.3.1",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz",
|
||||
"integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/motdotla/dotenv?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/emoji-regex": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"@discordjs/voice": "^0.16.0",
|
||||
"discord-player": "^6.6.1",
|
||||
"discord.js": "^14.11.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"pino": "^8.14.1",
|
||||
"pino-pretty": "^10.0.1",
|
||||
"yt-stream": "^1.4.8"
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
const pino = require('pino');
|
||||
const { minimumLogLevel, minimumLogLevelConsole } = require('../config.json');
|
||||
require('dotenv').config();
|
||||
|
||||
const transport = pino.transport({
|
||||
targets: [
|
||||
@@ -19,7 +19,7 @@ const transport = pino.transport({
|
||||
options: { destination: `./app-error.log` }
|
||||
},
|
||||
{
|
||||
level: minimumLogLevelConsole,
|
||||
level: process.env.MINIMUM_LOG_LEVEL_CONSOLE,
|
||||
target: 'pino-pretty'
|
||||
}
|
||||
]
|
||||
@@ -27,7 +27,7 @@ const transport = pino.transport({
|
||||
|
||||
module.exports = pino(
|
||||
{
|
||||
level: minimumLogLevel,
|
||||
level: process.env.MINIMUM_LOG_LEVEL,
|
||||
timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`,
|
||||
base: undefined
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user