Admin x360Labs Mod Xeon Posted May 16 Group: Admin Content Count: 9 Reputation: 14 Solved Content: 0 Days Won: 4 Admin Post Share Posted May 16 Hello, today I'll be releasing one of the bots I've made which can grab the banner image (and link) of any discord server it's in. There is two versions, a slash command version and a text command version. I have not combined them, this was a very fast project for me so the code may not be 10/10 but it runs in either configuration. Requirements - Node.js & Discord.js - A PC/Server to run the bot on - The ability to create discord applications in the developer portal, set intents, and configure bot and server permissions. Step 1: Install discord.js to your project directory, then create a file called "index.js" Step 2: Copy & paste the code below (either the slash command version OR the text command version) into the index.js file with your text editor of choice, then save it. Step 3: Run the bot through your console. On Windows this would be in a command prompt with the commands "cd <your project directory here>" followed by "node index.js" Slash command version: const { Client, GatewayIntentBits, REST, Routes } = require('discord.js'); const token = 'your bot token goes here'; // Replace with your actual token const clientId = 'your bots client id goes here'; // Replace with your bot's client ID const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages ] }); // Commands definition const commands = [ { name: 'banner', description: 'Displays the server banner' } ]; // Register commands globally const rest = new REST({ version: '10' }).setToken(token); (async () => { try { console.log('Started refreshing application (/) commands globally.'); await rest.put( Routes.applicationCommands(clientId), { body: commands } ); console.log('Successfully reloaded application (/) commands globally.'); } catch (error) { console.error(error); } })(); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; const { commandName } = interaction; if (commandName === 'banner') { if (!interaction.guild) { await interaction.reply("This command can only be used in a server."); return; } if (interaction.guild.bannerURL()) { const bannerUrl = interaction.guild.bannerURL({ format: 'png', size: 1024 }); await interaction.reply(`Server banner: ${bannerUrl}`); } else { await interaction.reply('This server does not have a banner set.'); } } }); client.login(token); Text command version: const { Client, GatewayIntentBits } = require('discord.js'); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessages ] }); const token = 'your bot token goes here'; // Replace with your actual token client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('messageCreate', message => { // Check if the message is a command and not from a bot if (!message.content.startsWith('!') || message.author.bot) return; // Extract the command const command = message.content.slice(1).trim().split(' ')[0]; if (command === 'banner') { console.log(`Command received: ${message.content}`); // Log only the command message if (!message.guild) { message.channel.send("This command can only be used in a server."); return; } // Fetching the banner URL if available if (message.guild.banner) { const bannerUrl = message.guild.bannerURL({ format: 'png', size: 1024 }); message.channel.send(`Server banner: ${bannerUrl}`); } else { message.channel.send('This server does not have a banner set.'); } } }); client.login(token); Screenshots: 2 Quote Link to comment Share on other sites More sharing options...
Support x360Labs Mod Zac Posted May 18 Group: Support Content Count: 35 Reputation: 32 Solved Content: 0 Days Won: 7 Share Posted May 18 i remember seeing you post something about this in the discord chat. Another thing to add to my resources folder for figuring out all this discord bot stuff.(never messed with it before) 1 Quote Link to comment Share on other sites More sharing options...
Admin x360Labs Mod Xeon Posted May 18 Group: Admin Content Count: 9 Reputation: 14 Solved Content: 0 Days Won: 4 Author Admin Post Share Posted May 18 4 hours ago, Zac said: i remember seeing you post something about this in the discord chat. Another thing to add to my resources folder for figuring out all this discord bot stuff.(never messed with it before) It could also easily be added as a command to an existing bot, I’ve just made it like this so it can be deployed and used by anyone who might come across this post. Also why I decided to embed the code instead of attaching files. I’ve actually got another thing to post which will be in this category at some point 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.