100 lines
3.3 KiB
JavaScript
100 lines
3.3 KiB
JavaScript
const { Client, GatewayIntentBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
|
const fs = require('fs');
|
|
require('dotenv').config();
|
|
|
|
|
|
|
|
// Add this at the top of your file
|
|
console.log('Starting bot...');
|
|
|
|
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.MessageContent
|
|
]
|
|
});
|
|
|
|
// Add this just before the login call
|
|
console.log('Attempting to log in...');
|
|
|
|
|
|
client.once('ready', () => {
|
|
console.log(`Logged in as ${client.user.tag}!`);
|
|
});
|
|
|
|
client.login(process.env.BOT_TOKEN).then(() => {
|
|
console.log('Login successful');
|
|
}).catch(error => {
|
|
console.error('Login failed:', error);
|
|
});
|
|
|
|
// Read the users.json file
|
|
const rawData = fs.readFileSync('users.json');
|
|
const rawUsers = JSON.parse(rawData);
|
|
|
|
|
|
// Remove user_id and player_id from each user object
|
|
const users = rawUsers.map(({ user_id, player_id, ...rest }) => rest);
|
|
|
|
// Now you can use the users array in your bot logic
|
|
console.log(`Loaded ${users.length} users`);
|
|
|
|
// Example: Find a user by username
|
|
function findUserByUsername(username) {
|
|
return users.find(user => user.username.toLowerCase() === username.toLowerCase());
|
|
}
|
|
|
|
|
|
client.on('interactionCreate', async interaction => {
|
|
if (!interaction.isCommand()) return;
|
|
|
|
const { commandName } = interaction;
|
|
|
|
if (commandName === 'ping') {
|
|
await interaction.reply('Pong!');
|
|
} else if (commandName === 'finduser') {
|
|
const username = interaction.options.getString('username');
|
|
const user = findUserByUsername(username);
|
|
if (user) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle(`User: ${user.username}`)
|
|
.setDescription(`Bio: ${user.profile.bio || 'No bio available'}`)
|
|
.addFields(
|
|
{ name: 'Country', value: user.profile.country, inline: true },
|
|
{ name: 'Rank', value: user.profile.rank || 'Unranked', inline: true },
|
|
{ name: 'Level', value: user.profile.level, inline: true },
|
|
{ name: 'Prestige', value: user.profile.prestige?.toString() || 'None', inline: true },
|
|
{ name: 'Current Level Badge', value: user.profile.current_level_badge || 'None', inline: true },
|
|
{ name: 'XP', value: user.profile.xp.toString(), inline: true }
|
|
)
|
|
.setColor('#0099ff');
|
|
|
|
if (user.profile.avatar) {
|
|
embed.setThumbnail(user.profile.avatar);
|
|
}
|
|
|
|
const row = new ActionRowBuilder()
|
|
.addComponents(
|
|
new ButtonBuilder()
|
|
.setLabel('🔵 View Profile')
|
|
.setStyle(ButtonStyle.Link)
|
|
.setURL('https://www.vrbattles.gg'), // Replace with your website URL
|
|
new ButtonBuilder()
|
|
.setLabel('🟡 Join Discord')
|
|
.setStyle(ButtonStyle.Link)
|
|
.setURL('https://discord.gg/your-invite-code') // Replace with your Discord invite URL
|
|
);
|
|
|
|
await interaction.reply({ embeds: [embed], components: [row] });
|
|
|
|
} else {
|
|
await interaction.reply('User not found');
|
|
}
|
|
}
|
|
});
|
|
|
|
// Use the bot token here
|
|
client.login(process.env.BOT_TOKEN);
|