const { Client, EmbedBuilder, GatewayIntentBits, ActivityType } = require('discord.js'); const axios = require('axios'); const intents = [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, ]; const client = new Client({ intents }); const token = 'none'; const serverStatusURL = 'https://bp.userr00t.com/serverbrowser/api/'; const myServerIP = '154.51.39.124'; const myServerPort = 5006; const serverListURL = 'https://brokeprotocol.com/servers.json'; const channelId = '1147674936694018079'; // Remplacez par l'identifiant de votre salon client.on('ready', () => { console.log(`Connecté en tant que ${client.user.tag}`); updateBotStatus(); }); async function updateBotStatus() { try { console.log('Starting bot status update...'); const axiosConfig = { timeout: 5000, headers: { 'User-Agent': 'YourBotName/1.0', }, }; console.log('Sending request to the server...'); const response = await axios.get(serverListURL, axiosConfig); console.log('Response received successfully.'); const serverList = response.data; const myServer = serverList.find(server => server.IP === myServerIP && server.Port === myServerPort); if (myServer) { const playerCount = myServer.PlayerCount; const playerLimit = myServer.PlayerLimit; // Set the bot's presence to show player count client.user.setPresence({ activities: [{ name: `${playerCount} players ingame `, type: ActivityType.Watching }], status: 'online', }); // Get the channel by its ID const channel = client.channels.cache.get(channelId); if (channel) { // Send a message to the channel when the server is online const embed = new EmbedBuilder() .setColor('#1aff00') .setFooter({ text: 'WarForce Staff', iconURL: 'https://media.discordapp.net/attachments/1059529244683808808/1157980189997928459/IMG_3092.webp?ex=651a9497&is=65194317&hm=641b5fd2a5de4fd0ae8aa3b0a8f79270485fffb3ffb4c0fa1a65fb22651adf54&' }) .setTitle('Statut Du Serveur') .setImage('https://media.discordapp.net/attachments/1059526042945081394/1157624190011187230/BCB36608-BF7A-4E8F-ADB7-FCE503E32247.jpg?ex=6519490a&is=6517f78a&hm=b570a7201960320c56a9b7fd7e78ae2f63e45ed3c0ce31b2552095c7f9df247a&') .setDescription(`Le serveur est en ON avec ${playerCount} joueurs connectés. <:on:1147676226484457612>`) .setTimestamp(); // Send the embed message channel.send({ embeds: [embed] }); } console.log(`Bot status set to: players`); } else { // If server not found, set presence to 'Server offline' client.user.setPresence({ activities: [{ name: 'Serveur OFF', type: ActivityType.Watching }], status: 'idle', }); // Get the channel by its ID const channel = client.channels.cache.get(channelId); if (channel) { // Send a message to the channel when the server is offline const embed = new EmbedBuilder() .setColor('#DF0000') .setFooter({ text: 'WarForce Staff', iconURL: 'https://media.discordapp.net/attachments/1059529244683808808/1157980189997928459/IMG_3092.webp?ex=651a9497&is=65194317&hm=641b5fd2a5de4fd0ae8aa3b0a8f79270485fffb3ffb4c0fa1a65fb22651adf54&' }) .setTitle('Statut Du Serveur') .setImage('https://media.discordapp.net/attachments/1059526042945081394/1157624190011187230/BCB36608-BF7A-4E8F-ADB7-FCE503E32247.jpg?ex=6519490a&is=6517f78a&hm=b570a7201960320c56a9b7fd7e78ae2f63e45ed3c0ce31b2552095c7f9df247a&') .setDescription(`Serveur est OFF <:off:1147676210848092352>`) .setTimestamp(); // Send the embed message channel.send({ embeds: [embed] }); } console.log('Bot status set to: Server offline'); } console.log('Bot status update completed.'); } catch (error) { console.error('Error updating bot status:', error); } } setInterval(updateBotStatus, 1 * 60 * 1000); client.login(token);