I'm trying to use shields.io to get my Discord bot's server count to render it on my website.
I tried to search for resources online; nothing helped. It would look like this for example: https://img.shields.io/badge/servers-10-orange
Related
I'm working on a discord bot website for a client, and he needs the real-time count on how many servers his discord bot is on, displayed in the website. I do not know about discord.js and couldn't find a simple answer.
These are the things I've done already:
Added the discord.js from node.js
Tried multiple solutions on StackOverflow(none gave me a correct answer)
let element = document.getElementById('serverCount')
let serverCount;
// This is where the code to get the discord bot server count should be
// It should be stored on the serverCount
element.textContent = serverCount
<h1 id="container">
Trusted by <b id="serverCount"></b> servers!
</h1>
Watched lots of tutorials but all of them were about coding the discord bot but I unfortunately couldn't understand a thing
You can get the count of servers your bot is in by:
await client.guilds.cache.fetch(); // update the chache for accurate info.
let serverCount = client.guilds.cache.size;
How are you?
I'm coding a Discord bot and I'm making a message leaderboard command, which displays up to 15 members with most messages (quick.db package to store data). Basically, It's alright when I run the code, but when someone who has so much messages and should appear in the leaderboard leave the server, it returns an error when I try to get the members tag and undefined in the message.
Is it possible to hide the user or delete them from the database?
What have I tried to solve the problem?
I tried to read Discord docs. and quick.db package to see if I can delete the user when they leave (using guildMemberRemove event), but what if they get back to the server?
οΎ
A better way is to delete user(lefted)* data from database once user left the server in guildMemberRemove event
I want to get number of members with a role, but always give me "1":
const server_roles = client.guilds.cache.get('server ID').roles.cache.get('role ID').members.size;
console.log(server_roles)
Log:
Real role member count = 4, not 1
The issue isn't within your code, it's to do with the information bots can access after a recent update. In order to fix this:
Go to your Discord Developer Application page https://discord.com/developers/applications/
Open your Discord bot application
In the left side menu, select Bot
Scroll down to Privileged Gateway Intents
Turn both toggles on next to PRESENCE INTENT and SERVER MEMBERS INTENT
Then, in the code, when initialising your Discord client, add this:
Discord.Client({ ws: { intents: Discord.Intents.ALL } });
That code assumes you've imported the module as Discord
It's quite complex, but after the recent update it's the only way to achieve what you want
I'm working on an emote bot for our text chat channels. I have it kind of working. The goal is that if a user types something like:
~hug #user
The bot sweeps up the message, removes it, and then emotes to the chat room:
| Joe hugs Jane. Awww!
This is working, but I'm using embed with a red border on the left side to make it look special. However this shows as a message from the bot, with the avatar picture, bot name, and such. What I'd like to do is have emotes show up without the bot name and such, like the announcement format when someone joins a server, etc.
Any advice on how to send a message formatted like that to a channel?
Unfortunately sending any messages that look like system messages, such as RECIPIENT_ADD, RECIPIENT_REMOVE, CALL, CHANNEL_NAME_CHANGE, CHANNEL_ICON_CHANGE, PINS_ADD or GUILD_MEMBER_JOIN is not possible using a Discord Bot.
This is a limitation of Discord itself and not a limitation of discord.js
You could, however, try to achieve a similar-ish looking result by using a webhook with a blank Avatar and Username.
message.channel.createWebhook('/*Webhook Name*/', "/*Webhook Avatar URL*/")
.then(w => w.send("your message here"));
I know you can list all the names of the Discord servers the bot is in using client.guilds.array() but is there a way to list all the ID's of the servers the bot is in?
I've tried many ways and I just can't figure it out.
I've tried "client.guilds.id", "client.guilds.array().id" and many other things I could think of but got no luck.
message.channel.send(client.guilds.id)
Something along the lines of this.
The errors I get trying this is: DiscordAPIError: Cannot send an empty message
This should work - message.channel.send(client.guilds.map(g => g.id).join("\n"))