mirror of
https://github.com/Sneed-Group/clanrocket-2
synced 2024-12-23 11:42:48 -06:00
Upload files to ''
This commit is contained in:
parent
ce48fa8f68
commit
ab8b848c74
2 changed files with 146 additions and 138 deletions
249
index.js
249
index.js
|
@ -1,121 +1,128 @@
|
||||||
require('dotenv').config(); // Load environment variables from .env file
|
require('dotenv').config(); // Load environment variables from .env file
|
||||||
const { Client, Intents } = require('discord.js');
|
const { Client, Intents } = require('discord.js');
|
||||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.MESSAGE_CREATE] });
|
const client = new Client({
|
||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
intents: [
|
||||||
const { REST } = require('@discordjs/rest');
|
Intents.FLAGS.GUILDS,
|
||||||
const { Routes } = require('discord-api-types/v9');
|
Intents.FLAGS.GUILD_MESSAGES // Add intents as needed
|
||||||
const QuickDb = require('quick.db');
|
]
|
||||||
const express = require('express');
|
});
|
||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
// Initialize Express.js app
|
const { REST } = require('@discordjs/rest');
|
||||||
const app = express();
|
const { Routes } = require('discord-api-types/v9');
|
||||||
const PORT = process.env.PORT || 3000;
|
const db = require('quick.db');
|
||||||
|
const express = require('express');
|
||||||
// Set up Quick.db
|
|
||||||
const db = new QuickDb.Database();
|
// Initialize Express.js app
|
||||||
|
const app = express();
|
||||||
// Set up Discord slash commands
|
const PORT = process.env.PORT || 3000;
|
||||||
const commands = [
|
|
||||||
new SlashCommandBuilder()
|
// Set up Discord slash commands
|
||||||
.setName('xp')
|
const commands = [
|
||||||
.setDescription('View your XP or someone else\'s XP')
|
new SlashCommandBuilder()
|
||||||
.addUserOption(option => option.setName('user').setDescription('The user to view XP for')),
|
.setName('xp')
|
||||||
new SlashCommandBuilder()
|
.setDescription('View your XP or someone else\'s XP')
|
||||||
.setName('addxp')
|
.addUserOption(option => option.setName('user').setDescription('The user to view XP for')),
|
||||||
.setDescription('Add XP to yourself or someone else (admin only)')
|
new SlashCommandBuilder()
|
||||||
.addIntegerOption(option => option.setName('amount').setDescription('The amount of XP to add'))
|
.setName('addxp')
|
||||||
.addUserOption(option => option.setName('user').setDescription('The user to add XP to')),
|
.setDescription('Add XP to yourself or someone else (admin only)')
|
||||||
new SlashCommandBuilder()
|
.addIntegerOption(option => option.setName('amount').setDescription('The amount of XP to add'))
|
||||||
.setName('removexp')
|
.addUserOption(option => option.setName('user').setDescription('The user to add XP to')),
|
||||||
.setDescription('Remove XP from yourself or someone else (admin only)')
|
new SlashCommandBuilder()
|
||||||
.addIntegerOption(option => option.setName('amount').setDescription('The amount of XP to remove'))
|
.setName('removexp')
|
||||||
.addUserOption(option => option.setName('user').setDescription('The user to remove XP from')),
|
.setDescription('Remove XP from yourself or someone else (admin only)')
|
||||||
].map(command => command.toJSON());
|
.addIntegerOption(option => option.setName('amount').setDescription('The amount of XP to remove'))
|
||||||
|
.addUserOption(option => option.setName('user').setDescription('The user to remove XP from')),
|
||||||
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
].map(command => command.toJSON());
|
||||||
|
|
||||||
(async () => {
|
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
||||||
try {
|
|
||||||
console.log('Started refreshing application (/) commands.');
|
(async () => {
|
||||||
|
try {
|
||||||
await rest.put(
|
console.log('Started refreshing application (/) commands.');
|
||||||
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID),
|
|
||||||
{ body: commands },
|
const applicationId = client.application?.id;
|
||||||
);
|
const guildId = client.guilds.cache.first()?.id;
|
||||||
|
|
||||||
console.log('Successfully reloaded application (/) commands.');
|
if (applicationId && guildId) {
|
||||||
} catch (error) {
|
await rest.put(
|
||||||
console.error(error);
|
Routes.applicationGuildCommands(applicationId, guildId),
|
||||||
}
|
{ body: commands },
|
||||||
})();
|
);
|
||||||
|
console.log('Successfully reloaded application (/) commands.');
|
||||||
// Discord.js event listener for when the bot is ready
|
} else {
|
||||||
client.once('ready', () => {
|
console.error('Unable to retrieve application or guild ID.');
|
||||||
console.log('Bot is ready!');
|
}
|
||||||
});
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
// Discord.js event listener for when a message is received
|
}
|
||||||
client.on('messageCreate', async message => {
|
})();
|
||||||
if (message.author.bot) return;
|
|
||||||
|
// Discord.js event listener for when the bot is ready
|
||||||
// Increment XP every 10 messages
|
client.once('ready', () => {
|
||||||
if (message.guild) {
|
console.log('Bot is ready!');
|
||||||
const xp = db.get(`xp.${message.author.id}`) || 0;
|
});
|
||||||
db.set(`xp.${message.author.id}`, xp + 1);
|
|
||||||
|
// Discord.js event listener for when a message is received
|
||||||
// Check if user leveled up
|
client.on('messageCreate', async message => {
|
||||||
const level = Math.floor(xp / 5) + 1;
|
if (message.author.bot) return;
|
||||||
const newLevel = Math.floor((xp + 1) / 5) + 1;
|
|
||||||
if (newLevel > level) {
|
// Increment XP every 10 messages
|
||||||
message.channel.send(`${message.author.username} leveled up to level ${newLevel}!`);
|
if (message.guild) {
|
||||||
}
|
const xp = db.get(`xp.${message.author.id}`) || 0;
|
||||||
}
|
db.set(`xp.${message.author.id}`, xp + 1);
|
||||||
});
|
|
||||||
|
// Check if user leveled up
|
||||||
// Discord.js event listener for when a slash command is used
|
const level = Math.floor(xp / 5) + 1;
|
||||||
client.on('interactionCreate', async interaction => {
|
const newLevel = Math.floor((xp + 1) / 5) + 1;
|
||||||
if (!interaction.isCommand()) return;
|
if (newLevel > level) {
|
||||||
|
message.channel.send(`${message.author.username} leveled up to level ${newLevel}!`);
|
||||||
const { commandName, options } = interaction;
|
}
|
||||||
|
}
|
||||||
if (commandName === 'xp') {
|
});
|
||||||
const user = options.getUser('user') || interaction.user;
|
|
||||||
const xp = db.get(`xp.${user.id}`) || 0;
|
// Discord.js event listener for when a slash command is used
|
||||||
interaction.reply(`${user.username} has ${xp} XP.`);
|
client.on('interactionCreate', async interaction => {
|
||||||
} else if (commandName === 'addxp') {
|
if (!interaction.isCommand()) return;
|
||||||
if (!interaction.member.permissions.has('ADMINISTRATOR')) {
|
|
||||||
return interaction.reply('You do not have permission to use this command.');
|
const { commandName, options } = interaction;
|
||||||
}
|
|
||||||
|
if (commandName === 'xp') {
|
||||||
const amount = options.getInteger('amount');
|
const user = options.getUser('user') || interaction.user;
|
||||||
const user = options.getUser('user') || interaction.user;
|
const xp = db.get(`xp.${user.id}`) || 0;
|
||||||
const currentXp = db.get(`xp.${user.id}`) || 0;
|
interaction.reply(`${user.username} has ${xp} XP.`);
|
||||||
db.set(`xp.${user.id}`, currentXp + amount);
|
} else if (commandName === 'addxp') {
|
||||||
interaction.reply(`${amount} XP added to ${user.username}.`);
|
if (!interaction.member.permissions.has('ADMINISTRATOR')) {
|
||||||
} else if (commandName === 'removexp') {
|
return interaction.reply('You do not have permission to use this command.');
|
||||||
if (!interaction.member.permissions.has('ADMINISTRATOR')) {
|
}
|
||||||
return interaction.reply('You do not have permission to use this command.');
|
|
||||||
}
|
const amount = options.getInteger('amount');
|
||||||
|
const user = options.getUser('user') || interaction.user;
|
||||||
const amount = options.getInteger('amount');
|
const currentXp = db.get(`xp.${user.id}`) || 0;
|
||||||
const user = options.getUser('user') || interaction.user;
|
db.set(`xp.${user.id}`, currentXp + amount);
|
||||||
const currentXp = db.get(`xp.${user.id}`) || 0;
|
interaction.reply(`${amount} XP added to ${user.username}.`);
|
||||||
db.set(`xp.${user.id}`, Math.max(0, currentXp - amount));
|
} else if (commandName === 'removexp') {
|
||||||
interaction.reply(`${amount} XP removed from ${user.username}.`);
|
if (!interaction.member.permissions.has('ADMINISTRATOR')) {
|
||||||
}
|
return interaction.reply('You do not have permission to use this command.');
|
||||||
});
|
}
|
||||||
|
|
||||||
// Start the Express.js server for the XP API
|
const amount = options.getInteger('amount');
|
||||||
app.get('/xp/:guildId/:userId', (req, res) => {
|
const user = options.getUser('user') || interaction.user;
|
||||||
const guildId = req.params.guildId;
|
const currentXp = db.get(`xp.${user.id}`) || 0;
|
||||||
const userId = req.params.userId;
|
db.set(`xp.${user.id}`, Math.max(0, currentXp - amount));
|
||||||
const xp = db.get(`xp.${userId}`) || 0;
|
interaction.reply(`${amount} XP removed from ${user.username}.`);
|
||||||
res.json({ guildId, userId, xp });
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
// Start the Express.js server for the XP API
|
||||||
console.log(`XP API server is running on http://localhost:${PORT}`);
|
app.get('/xp/:userId', (req, res) => {
|
||||||
});
|
const userId = req.params.userId;
|
||||||
|
const xp = db.get(`xp.${userId}`) || 0;
|
||||||
// Login to Discord
|
res.json({ userId, xp });
|
||||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
});
|
||||||
|
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`XP API server is running on http://localhost:${PORT}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Login to Discord
|
||||||
|
client.login(process.env.DISCORD_BOT_TOKEN);
|
||||||
|
|
35
package.json
35
package.json
|
@ -1,17 +1,18 @@
|
||||||
{
|
{
|
||||||
"name": "ClanRocket",
|
"name": "ClanRocket",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Discord bot for managing XP in a clan server",
|
"description": "Discord bot for managing XP in a clan server",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js"
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/builders": "^1.7.0",
|
"@discordjs/builders": "^1.7.0",
|
||||||
"discord-api-types": "^0.24.0",
|
"@discordjs/rest": "^2.2.0",
|
||||||
"discord.js": "^13.4.1",
|
"discord-api-types": "^0.24.0",
|
||||||
"express": "^4.17.1",
|
"discord.js": "^13.4.1",
|
||||||
"quick.db": "^9.1.7",
|
"dotenv": "^10.0.0",
|
||||||
"dotenv": "^10.0.0"
|
"express": "^4.17.1",
|
||||||
}
|
"quick.db": "^9.1.7"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue