#development
1 messages · Page 867 of 1
something wrong with permission overwrites
If you are on v12, you provide the array as the first param, not an object https://discord.js.org/#/docs/main/stable/class/GuildChannel?scrollTo=overwritePermissions
@cinder patio gotta look that
Also, you can provide permission overwrites in the options argument of the create method
wdum
.create(name, {
type: "text",
permissionOverwrites: [...]
});```
ok sure but that way you are making less requests to discord so the code is generally faster and more efficient
Ok so its like
.create(name, {
type: "text",
permissionOverwrites: [ {
id: message.author.id,
allow: ['VIEW_CHANNEL'],
},
{
id:guild.id,
deny: ['VIEW_CHANNEL'],
}]
});```
yup
Perfect then
Help me write a command for a bot on Python
That-would at the mention of ovner, the bot removed the mention
I can't think of it)
@unique patio I can't code on py but here is how u can do :
-bot.on_message
-if msg.content == '<@ownerid>' msg.delete()
But even with that owner will still got the notif
If he gets pinged
If the essage is not only pinging
it won't work
bether doing like
msg.contains("<@" + ownerid + ">")
Msg.content.contains ?
I can't code in py @earnest phoenix
@tight plinth But the person who made the ping will not know that the owner received the notification, and will no longer ping 😂
If it spams , I'll ban it 🙂
Well, if I am on a server where I am not an admin, then the server is important to me, and important servers will not be pinged just like that
wut
Watt
where is the logic behind that 
Why do you want your bot to do it anyways
She's gone
Whatt
I don't really understand what you want from me 😂
Not doing that
const collector = new Discord.ReactionCollector(reactionRolesMessage, filter);
collector.on('collect', (reaction, user) => {
console.log('lol');
});
collector.on('remove', (reaction, user) => {
console.log('lol2');
});``` why does 'collect' work but 'remove' doesn't? I'm just following the docs: https://discord.js.org/#/docs/main/stable/class/ReactionCollector?scrollTo=e-remove
I think i had this same problem awhile ago, but I got it to work. You have to add on option for the reactionCollector called dispose
https://discord.js.org/#/docs/main/stable/typedef/CollectorOptions
maybe something like this would work
const collector = new Discord.ReactionCollector(reactionRolesMessage, filter, { dispose: true});
is value ? true : false working on nullable values?
yes
if value is null, which one will it be? true or false ?
false
(and also empty strings)
@hollow granite thank you!
does anyone know how to return if you mention someone or your message starts with <@
message.guild.roles.cache.find()
@royal portal which lib
if(message.mentions.users.first()) return;
in discord.js, Message object has a mentions method
it's not a method, it's a property
@spare goblet
discord.js
sorry'p
@earnest phoenix https://discordjs.guide/additional-info/changes-in-v12.html
member.roles is somehow not defined
and that is because
member is not a user object
let { member } = message;
member.roles.add(role)
message.author returns a user object, you need a member object, which is message.member
How can i force my invitation url to be condom like and be used only one time ?
just found on doc
bruh
client.on('guildMemberAdd', member => {
var role = member.guild.roles.cache.find(role => role.name === 'verify');
member.roles.add(role);
const rando_imgs = [
'https://cdn.discordapp.com/attachments/648627056246259738/689454008427085851/Sayori_Illustration.png',
'https://cdn.discordapp.com/attachments/648627056246259738/689454069361672257/paint-stripe-png-16.png',
'https://cdn.discordapp.com/attachments/648627056246259738/689454107236630635/Untitled-434554.png',
'https://cdn.discordapp.com/attachments/648627056246259738/689457427447283808/Untitled-434554-Recovered-Recovered.png',
'https://cdn.discordapp.com/attachments/648627056246259738/689458587461746725/midoriya_izuku__render__444_by_fania98_dd75ho3-pre.png',
];
const embed = new Discord.MessageEmbed()
.setTitle(` Welcome to ${member.guild.name} `)
.setColor(0xffb700)
.setThumbnail(`${member.user.displayAvatarURL}`)
.setDescription(`Welcome ${member} to **${member.guild.name}** dont forget to read the rules and enjoy the server`)
.setImage(rando_imgs[Math.round(Math.random() * (rando_imgs.length - 1))])
.setFooter(`© ${member.guild.name} 2020 - 2021` )
.setTimestamp()
member.guild.channels.cache.find(ch => ch.name === "welcome").send(embed);
});
client.login(token);
``` its not sending the embed but it is giving me the role what did i do wrong
You should firstly, check if the role exists, then add it.
Same with the channel, if the channel exists, then send the message.
const Discord = require("discord.js");
const quickdb = require("quick.db")
const Guild_data = new quickdb.table("lang")
exports.run = async (bot, message, args) => {
let server = message.guild.id;
if(!message.member.hasPermission("MANAGE_GUILD")) return message.channel.send("**🇫🇷 Vous devez avoir la permission `MANAGE_GUILD` afin d'effectuer cette commande.\n\n🇺🇸 You must have permission `MANAGE_GUILD` to do this command.**")
if(!args[0] || args[0] !== "fr" || args[0] !== "en") {
return message.channel.send("**🇫🇷 Langues disponibles / 🇺🇸 Available languages :\n\n↪️ `f.setlang fr` : Selectionne la langue française / Select french language.\n↪️ `f.setlang en` : Selectionne la langue anglaise / Select english language.**")
}
Guild_Data.set(`${server}.lang`, args[0]);
if(args[0] === "fr") {
message.channel.send("** La langue par défaut est maintenant `🇫🇷 Français`.**")
} else if(args[0] === "en") {
message.channel.send("** The default language is now `🇺🇸 English`.**")
}
}
exports.help = {
name: "setlang"
}```
when I make the command f.setlang fr or f.setlang en the bot puts me that the message of the available languages
ues
ty
good
What you should do is this:
can anyone help me from yesterday? :/
when I unban someone and I do -unban user then
if (args[0] === "fr") {
//code
} else if (args[0] === "en") {
//code}
} else {
//code
}
lemme check your code
Ok thx
well
i think its the
return part
on //
// check if banneduser
the mentions.user.size
I want it to return if the person mentions user
bannedMember.user.id might work
what about it
just do message.mentions.users.size === 0
const quickdb = require("quick.db")
const Guild_data = new quickdb.table("lang")
exports.run = async (bot, message, args) => {
let server = message.guild.id;
if(!message.member.hasPermission("MANAGE_GUILD")) return message.channel.send("**🇫🇷 Vous devez avoir la permission `MANAGE_GUILD` afin d'effectuer cette commande.\n\n🇺🇸 You must have permission `MANAGE_GUILD` to do this command.**")
if(args[0] === "fr") {
Guild_Data.set(`${server}.lang`, args[0]);
return message.channel.send("** La langue par défaut est maintenant `🇫🇷 Français`.**")
} else if(args[0] === "en") {
Guild_Data.set(`${server}.lang`, args[0]);
return message.channel.send("** The default language is now `🇺🇸 English`.**")
} else {
return message.channel.send("**🇫🇷 Langues disponibles / 🇺🇸 Available languages :\n\n↪️ `f.setlang fr` : Selectionne la langue française / Select french language.\n↪️ `f.setlang en` : Selectionne la langue anglaise / Select english language.**")
}
}
exports.help = {
name: "setlang"
}```
leny32 is good?
Should be, try and see.
k thx
@royal portal what exactly do you want? you want your unban command to not unban if there are mentioned users?
yeah
well, NMW has already told you the line. You're double negating, so remove both "!"
like he said, message.mentions.users.size === 0
i did
and what exactly is happening now?
i'm going to check
still
discordapierror
invalid form body
value user id is not snowflake
show error location
how would i know that
check error message
send screenshot
-.
or console.log(err.stack)
0|kitty | DiscordAPIError: Invalid Form Body
0|kitty | user_id: Value "@bright radish" is not snowflake.
0|kitty | at RequestHandler.execute (/home/pi/Desktop/Other/DiscordBot/node_modules/discord.js/src/rest/RequestHandler.js:170:25)
0|kitty | at processTicksAndRejections (internal/process/task_queues.js:97:5) {
0|kitty | name: 'DiscordAPIError',
0|kitty | message: 'Invalid Form Body\n' +
0|kitty | 'user_id: Value "@bright radish" is not snowflake.',
0|kitty | method: 'get',
0|kitty | path: '/users/@bright radish',
0|kitty | code: 50035,
0|kitty | httpStatus: 400
0|kitty | }
or console.log(err.stack)
@summer torrent
this is the cause of the error: client.users.fetch(args[0])
so you need to move this if(message.mentions.users.size) return; to before that line
and change it to that, not the !... === 0 way
we can't help you for bot makers
just try it and see
Hi. I did some stupid things with my bot that's hosted on Heroku (I will soon get another host for it, don't worry). It doesn't start anymore after I push it to Github. Automatic deployment is still on and I saw I deleted the Procfile yesterday, but I recovered that. Does Heroku require other files as well? I guess I have to configure the starter file somewhere on their website too, but I can't find it.
client.on('message', message => {
if (message.content.startsWith('mb!avatar') {
if (!message.mentions.users.size) {
return message.channel.send(`Your avatar: ${message.author.displayAvatarURL}`);
}
const avatarList = message.mentions.users.map(user => {
return `${user.username}\'s avatar: ${user.displayAvatarURL}`;
});
message.channel.send(avatarList);
})});
```^^ My **code**
/home/container $ node app.js
/home/container/app.js:1222
if (message.content.startsWith('mb!avatar') {
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
you didn't end your if()
anyone help?
yeah it's not right
I need a cool help command js . Can someone give me?
"cool"
please do
you can start with learning more about promises
because this await users.fetch(id).then().catch(console.error) kinda makes no sense
and this makes even less sense js try { message.guild.members.unban(bannedMember).then().catch(console.error); logsChannel.send(embed).then().catch(console.error); } catch(e) { console.log(e.message) }
client.on('message', message => { if (message.content.startsWith('mb!avatar') { if (!message.mentions.users.size) { return message.channel.send(`Your avatar: ${message.author.displayAvatarURL}`); } const avatarList = message.mentions.users.map(user => { return `${user.username}\'s avatar: ${user.displayAvatarURL}`; }); message.channel.send(avatarList); })}); ```^^ My **code**/home/container $ node app.js
/home/container/app.js:1222
if (message.content.startsWith('mb!avatar') {
SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:656:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
@earnest phoenix I did, I think... 
or where should I place the extra )
@quartz kindle Can you help me please 🥺
well im just gonna scrap ban and unban
you just have to end your if statement
proper syntax is the basics of js
Hi. I did some stupid things with my bot that's hosted on Heroku (I will soon get another host for it, don't worry). It doesn't start anymore after I push it to Github. Automatic deployment is still on and I saw I deleted the Procfile yesterday, but I recovered that. Does Heroku require other files as well? I guess I have to configure the starter file somewhere on their website too, but I can't find it.
nvm I'm dumb 😂
Have you chosen a library yet?
which language do you use
Learn how to code first ?
Do you have any programming knowledge at all?
If not, go to somewhere like codecademy first and learn
(prefixs, embeds, !ping) don't conclude "basics"
Those are just specific properties and features in this domain.
In conclusion, you need to learn computing basics or basic programming concepts.
To learn, in fact, and form a base you then build on more and more knowledge.
If you've done roblox stuff I assume you know a bit of lua?
Javascript is vaguely similar to lua so it would be easiest for you to learn that
^ 
Get on codecademy and try to understand basic javascript, then get on Discord.JS Guide and look through there
You're welcome
Good luck
Javascript is vaguely similar to lua so it would be easiest for you to learn that
As close as a chimp is to a fish, but yeah, considering only the non-typed vars and not being compiles langs they are similar
Idk they kinda look similar to me
Anyone know what the maximum speed you can update a html tag
I'm trying to animate my bot stats counting up but one of the stats its still counting up when all the rest are finished so I need to do some math to calculate the step (atm I'm using 1)
Nvm fixed it
(node:7060) UnhandledPromiseRejectionWarning: TypeError: message.member.roles.find is not a function
if (message.content.startsWith(">>selectbot")) {
if(!message.member.roles.find(r => r.name === "customer")) { message.channel.send("Not a customer")}
}
what discord.js version?
In discord.js how can I find the id of the everyone role?
Last one @quartz kindle
it's the guild id
14
last one is v12
@earnest phoenix roles.cache.find()
That will send an embed and then instantly delete it I think
I assume you want to wait 1 second before deleting it?
I think you have to put {timeout:1000}
But idk
How can I make it??? Any hint
Is '''msg.channel.send(embed).then(msg.delete(1000))''' correct
@earnest phoenix thats not correct
.then(m => m.delete(1000))
if you're using v12, there are options
Oh yes
m.delete({ timeout: 10000 })
That for 12
yea
K
or await
Thx
const sentMsg = await msg.channel.send(embed);
sentMsg.delete({ timeout: 10000 });
Hey how do I gets started learning to make a bot that screenshots a window then sends it to mail or discord?
10000 is 10s right
yes
reduce
K
K thx
Hey how do I gets started learning to make a bot that screenshots a window then sends it to mail or discord?
@earnest phoenix you can't, unless you want to sc your own window
huh
How can I make it??? Any hint
@robust moth how can you make what? the prefix?
so you are saying this cant be done?
which window do you want to screenshot?
a game
yep, bots normally run in virtual servers, so they can't actually see a "screen"
the only way to do that is to run the bot inside the same machine where the game is running
or to run a program that does it and then sends it to the bot
doesnt need to be a discord bot just a bot that screenshot and sends image
as I said, UNLESS you are running the bot on your own machine, in this case it wouldn't be a bot but a sc application
damn, tim is too ninja
you need to look into screen capturing solutions and software
and screen capturing APIs if you're developing on your own code
which language do you know?
None
then im sorry, but that is most likely too advanced for a beginner
In this tutorial you will learn how to capture the screen using Java API's. We are using Robot class object which will get the coordinate system of the primary screen and base on co-ordinates we will constructs the output image.
with java it's mostly straightforward
but still, as tim said, too much for a beginner
Ok thanks for time i will learn java
or just use ffmpeg
ffmpeg allows screen capture
or you could use something like shareX, which apparently has a CLI you could interface with
yeah, there are good solutions on the internet
but since he asked for "how to make" I suggested that
Can it automatically capture a screenshot at given interval?
I think most people here havnt attempted something like this
Before I waste my time, if I send data from one nodejs server to another (with a self signed cert) and then forward the data from the second nodejs server to my website, will it appear as a secure connection on the webpage? (I'm using aws for my bot and glitch for my site, hence the bodge)
Wait idk if that would even work to begin with lol
you can create your own shareX uploader that posts it where you want
Glitch said a port was already in use so I did this and it still refuses to work
Conclusion: Glitch bad
Because: free
glitch only allows 3000
Tried 3000 as my first attempt, then 8000, then 8080
You should consider getting a VPS, you can get one for like $3/month.
Oh, ok.
The while loop is still going and has tried over 120k ports lol
Thanks
Port 25565, someone trying to host a minecraft server on glitch? XD
Very cool

oh no, xD
Wait if only port 3000 is exposed does that mean I can't have an inbound and outbound connection?
Why would you use glitch to host the project anyways?
Can't you setup another project on the VPS?
Right so I have my bot, I need to get some data to my website (which is on glitch until I have money for domains) but my website now appears as insecure because the connection between the vps and glitch is on a self-signed cert
So I was trying to pull that data to a glitch nodejs server and then forward it on to my site so it all appears secure
Use cloudflare?
For what?
If you're using a website
If you want a SSL Certificate
Oh I get you now
https (secure)
Yeah
Whenever I go to the page it says https so I'd use cloudflare to make it secure?
Cloudflare should work, yes.
No problem :)
does anyone know if there is a reddit api
yes
is there a discord guild for it?
for what? reddit?
the reddit api praw
i tried adding a server (that is on top.gg/servers) to my bot page using the ID but its not showing on the site
did i do something wrong?
^
How to get a role?
wrong channel
which role
var role = message.mentions.roles.first() || message.guild.roles.get(args[1]) || message.guild.roles.get(r => r.name === args[1])
is this correct?
did
didnt work
logged args[1]
then it isn't correct
@fossil oxide Youre still accepting hand written applications yeah?
For certification
@bitter sundial ^ 👀
im not the best at css but i cant seem to change the color of this, ive tried doing color="" and adding it to css, and i tried making a class too but i guess im doing something wrong
for some reason color="" worked with other lines but not that
You shouldn't need speech marks.
Just do color: #FFFFFF or any other colour you want.
Although this should be in #general
Nope, only bot development.
That needs to be inside your css tag
i had it in my css tag but it didnt seem to change
however i tried the thing starman told me and it worked
even tho for my body color="" worked
How can I check if a user whose ID I know is connected to a specific voice channel? [Discord.js]
what is your djs version
12
console.log(`User with ID ${vote.user} just voted!`);
let embed = new Discord.RichEmbed()
.setColor(`#5780cd`)
.setAuthor(`<@${vote.user}> Upvote !`)
.setTimestamp()
.addField(`User ${vote.user} With ID ${vote.user} Just Upvote For my Bot `, `He UpVote in https://top.gg/bot/688364176305029132 `)
.addField(`We Have ${vote.count} UpVotes `, `Thanks You Soo Much`)
let guild = Client.guilds.cache.get(`698495495236223026`)
Client.channels.cache.get(698648416825245777).send(embed)
});```
```(node:7584) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined```
What's wrong?
Client.channels.cache.get(698648416825245777).send(embed)```
channel ID must be a string
Ah, okay
I am using discord.js v12.1.1
I am trying to get an invite from a guild the bot is on.
https://hasteb.in/ebetudow.coffeescript
But it keeps on saying the bot is not in that guild when it is in it....
Can some one help?
to give someone roles, you would need to have manage roles right?
console.log(`User with ID ${vote.user} just voted!`);
let embed = new Discord.RichEmbed()
.setColor(`#5780cd`)
.setAuthor(`<@${vote.user}> Upvote !`)
.setTimestamp()
.addField(`User ${vote.user} With ID ${vote.user} Just Upvote For my Bot `, `He UpVote in https://top.gg/bot/688364176305029132 `)
.addField(`We Have ${vote.count} UpVotes `, `Thanks You Soo Much`)
let guild = Client.guilds.cache.get(`698495495236223026`);
Client.channels.cache.get(`698648416825245777`).send(embed);
});```
```(node:7724) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of undefined```
How do I disconnect a user from a voice channel in discord.js?
@plucky heart which ver are you on
npm discord.js --version
6.13.7
@balmy knoll setVoiceChannel(null)
thats the npm version
v6 doesnt work
not discord.js version
^^
to get a package version you use npm ls discord.js
@plucky heart .cache only exists in v12, not in v11
you're probably using v11, as you're using RichEmbed, which only exists in v11
@summer torrent Thanks. How can I check if the user whose ID I know is connected to a specific voice channel?
I updated to discord.js@12.1.1 and console shows
^
TypeError: member.guild.roles.find is not a function
roles.cache.find
@summer torrent 12.1.1
<GuildMember>.voice.channel```
@summer torrent And this return me the channel ID?
np
@summer torrent I have got this error: TypeError: Cannot read property 'channel' of undefined
maybe your "member" is not connected to any voice channel
@summer torrent No, i'm testing it and i'm connected
show your code
@plucky heart if you updated to v12 then there are a LOT of things you will need to change
Yes
@summer torrent
if (user.voice.channel.id == "698608221275029590")
{
// Manageable User Check
if(!user.manageable)
{
// Unable to kick the user
var unableEmbed = new Discord.MessageEmbed()
.setColor("RED")
.setDescription(
`:exclamation: **Non riesco ad espellere <@${user.id}> dal canale vocale.**`
);
message.channel.send(unableEmbed);
} else {
// Kick the user
user.setVoiceChannel(null);
message.react("✅");
}
} else {
message.channel.send(notconnectedEmbed);
}
what is "user"
(Sorry for the message, i'm italian)
@summer torrent const user = message.mentions.users.first();
users dont have voice, members do
@summer torrent Wait... I don't understand. Where have i to replace user with member?
@summer torrent
const user = message.mentions.users.first();
@balmy knoll
replace users with members
User object don't have voice
^
TypeError: fn.bind is not a function```
what?
update node js
discord.js v12 requires node.js v12 or higher
I am using discord.js - v12.1.1
I am trying to get an invite from a guild the bot is on.
https://hasteb.in/ebetudow.coffeescript
But it keeps on saying the bot is not in that guild when it is in it....
I updated the node js and still the same
updated to which version
@heavy marsh you are declaring invitechannels inside broadcastEval, then trying to use it outside of it
that wont work
+ node.js@0.0.1-security
added 1 package and audited 12225 packages in 5.092s
5 packages are looking for funding
run `npm fund` for details
oh
node.js is the environment
ooh ...

then its already updated
but the console still shows
^
TypeError: fn.bind is not a function```
https://hasteb.in/cemovora.js Like this?
your error is likely caused by trying to use .find("key","value") which was deprecated a long time ago and is not supported, and finally removed recently
What to do with this error?
@plucky heart read this https://discordjs.guide/additional-info/changes-in-v12.html#collection
everything you need is there
@summer torrentHelp me again 😄. I use user.setVoiceChannel(null); to disconnect an user from a voice channel, but i have got an error: TypeError: user.setVoiceChannel is not a function.
https://oliy.is-just-a.dev/lv7twc_3545.png https://oliy.is-just-a.dev/9mdqpa_3546.png it doesnt exist in user or guildmember
<GuildMember>.voice.setChannel
@summer torrent @amber fractal Thanks
np
Hi who can help me set my DC server API kay?
What key?
Just Discord server API
did you read this? https://umod.org/plugins/discord-core
I need because i runned RUst game server and i want connect
Webhooks?
No just webhooks,plugin want api kay nad guild id and much more
all have but api no
Tim i visited yes
i chack again
Oh, you mean a bot api key.
Yes 😄
I was like, "what sever api key, this I need to know" xD
😄
am i just fucked if a feature i want to implement requires a new permission?
or can i prompt existing servers to update the bot perms?
You can just ask if they have a missing permission.
just add to the needed command to make a if the bot doesn't have enough permission; and ask them to add the permission.
what do you mean by ask?
can you prompt a popup or something
or are you talking about automating a dm to the server owner asking them to reinvite the bot?
Well, you could always ask users for updating the permission if they have role/ permission which can do so.
So no, you're not doomed.
just check for the permission when the feature is used, and if it doesnt have, show an error saying that it requires it
Yes.
Bugg.... Need help
we can't understand anything from video
What's the issue?
If you want people to be able to assist you, please provide more information, such as what library and language you're using, the code in question and what you are trying to do and/or what is causing the error.
which sweaty mod did that?
🙂
Ted
lul he is doing his job
will my vps provider ban me soon like this?
CPU is jumping between 50 % and 200% for both containers
@summer torrent when I mention my bot in server 1 then bot reply prefix bdr(default "bdr") but when I mention my bot in server 2 then first time reply prefix bdr (default"m") and second time reply prefix m
reveal yourself shivaco
What's the code Mr. Who?
@elder vine
let user = message.mentions.users.first();
let bot = message.client.user;
//let client = message.client
// console.log(user, bot, client);
if (user === bot) {
let embed = new discord.MessageEmbed()
.setColor("RANDOM")
.setTitle(`ℹ️ My Current Prefix Is \`[${message.client.prefix}]\`\n Use \`[${message.client.prefix}help]\` To See All Commands`)
return message.channel.send(embed).catch(console.error)
}
};```
Does it use custom prefix?
@elder vine yes
because you are using message.client.prefix, it will be the same prefix for every guild
does discord.js cache guilds like that?
that would work if you never reset the bot
what do you mean cache guilds like that?
No, if you store it in a Collection (array) you could do that. But it wont save after restart of bot
yeah, you need some type of database system to store configuration for guilds
yeah
i wouldn't assume it returns the same object when you call get unless it literally caches every guild object it sees
if you are only storing preifx, you could use a json because it would be small
Or just get right in the use of something like MongoDB - which is free as well.
@elder vine
if you're just doing prefixes or other small amounts of data, i'd recommend some simple protocol like JSON for saving basic config
Oh, you use json
will my vps provider ban me soon like this?
CPU is jumping between 50 % and 200% for both containers
@elder vine yeap
no, dont do that Mr. Who
It depends on your provider @viral spade - but they shouldn't, however they will most likely ask you to upgrade your VPS.
I would only use JSON if its static data
@elder vine ok, but does it mean this cpu will not be able to handle more servers?
dont use json for anything beside static data
i would use sqlite if i only store prefixes
you can read the file and only store the value for the guildid
idk about light minimal nosql dbs
@knotty steeple it's tested
if you only need to store less than 100 prefixes, you should be fine
@knotty steeple it's fine if you're just storing a few really simple config options
@elder vine 3
but I do agree with everyone as it should only be used for more static data
i cant agree with that 
it's not entirely worth setting up an entire database if you're just going to store custom prefixes by server
yeah
in general no
What's the issue @jovial finch ?
JSON is Not for dynamic data and shouldnt be used for it
a simple sqlite db takes seconds to make
@elder vine The bot is in 14k servers.
Well, then you maybe should look to upgrade your CPU.
Which VPS provider are you currently using?
contabo
How much you currently paying monthly, if I may ask?
30
And how much are you running on, like CPU power and RAM etc.?
i'm personally against SQL so i wouldn't use it, but if it's that easy to set it up, then might as well use it
i was think about getting a dedicated 45 euro/month hetzner
whats ur specs
Yea, specs for the VPS.
Then you might just gotta look for some improvements in the code.
how many shards?
Is the bot very CPU intensive itself, per guild?
too many shards for the amount servers. i just increased to 25
How many shards per server?
yes it is cpu intensive
what does the bot do?
i keep it between like 700 and 1000 guilds per shard
do you need presence updates?
yesi need, it does statistics
well rip
Is it needed tho?
which library?
discord.js
did you install zlib-sync?
no doesnt say anything to me
install zlib-sync
node module?
yes
ok let me read about it a sec
you might also want erlpack, bufferutil and utf-8-validate
all those libraries increase performance by offloading heavy-computing operations to native C code instead of javascript
especially zlib-sync
you can expect about 50% less cpu usage after installing those
interesting
ooo
i dont understand how to "attach" the module to my bot
oh nice
Oh, cool.
So how can i know how loaded my cpu really is? i mean those values ranging over 200% dont really tell me at what % am actually at
you need to monitor cpu usage over time
idk what kind of containers you're using, but stuff like pm2 can monitor a process's cpu usage
also stuff like top/htop
well time to get those packages
i think pm2 on top of containers is overkill, no?
native c code for performance 😩 👌
pm2 monit
well what i showed you is the docker stats command
pm2 is good even with python.
does it update in real time?
yes
or just shows you a snapshot?
yes approx once per sec
real time and there's also a web browser for you remotely if you wish to control it.
then i guess you will just see how far does it jump up and down lol
you said between 50% and 150% right?
sometimes its 300%
average is definately above 100%
the average numbers you'll see
other than that, you'd probably need to use a proper resource monitoring system
with graphs and shit
do you think will this problem also be reduced by a dedicated machine?
like compared in the power/cost relation
well, the good old "throw more hardware at it" will probably work, but its not really the most effective way
i mean thats why i said in terms of power/cost
Nah vertical scaling best scaling 
in the long run, working on optimizing performance will give you better results
these optimization i can do in any case, ayn time
although the biggest performance cost is by far presence packets lol
does your bot do music/audio?
I think it's an activity bot.
no only activity tracking. activityrank.me. you can see some stats there
you could use intents to disable stuff you dont need, such as typing updates, but that wont make too much of a difference i guess, presence updates are 10 times more frequent
but give zlib-sync a try and see how it goes
So my thinking is:
I have a 30€/m 64gb machine, while the bot needs 20gb (this can also be reduced, i know) for its current 14k servers.
so, in any case, however big i upgrade my hardware, i will have not enough cpu power and too much memory. Even with 50% less cpu power needed, the relation between cpu and memory usage does still not fit the vps.
So i was wondering if a dedicated 45€/m 64gb machine will give me a better cost per server, because of more fitting relation between cpu and ram for my program?
sorry, is that 20gb of ram?
yes
holy fuck dude
damn that's a lot for 14k servers
Spotify is in 52k and uses 5GB unoptimised
@royal portal just send Emoji object
or ^
so i just type that
so
becomes !002_rainbow
and it will do it
yup
yeah
as a string
a string?
@viral spade you could look into high-cpu machines, but they are much more expensive
cpu cost is much higher than ram cost
You can type \:emoji: in chat to get it.
That is just insane usage tho
a dedicated machine can also be an option if it has 24/32 cores or more
like there has gotta be some major ram leaks
the 14k servers use 7gb of ram after 2 hours of running. the 20gb is the amount i need to let both the bot and the database run + it should be able to run a long time and have even more ram than it needs to account for spikes. so my machine should have 20gb for my 14k servers, but the bot itself need less
its just discord.js being discord.js
gotta cache everything
i rises to 12gb after a day or so
Who can give me bot infrastructure
but memory is not my probel. only cpu
wait so i dont put the emoji in " " ?
you do
gotta cache everything
gotta cache 'em all
^
sa
can't say tick if you do it this way
sad
bots get free nitro
u and me cry @royal portal
not really
:/
they only really get the emoji thing
if i double the amount of shard for the same amount of servers, does it take considerably more cpu power or is it just a little overhead?
assuming the bot only does responsive thing on events
still doesnt work
.setDescription("<a:animatedtic k1:661900429432455187> Restarted.")
ignore the space
is it because it needs `?
Are there any errors? @royal portal
nope
You need to use the client to get the emoji's, store it in a variable and then reference it in the message.
@viral spade any number of shards above core count will increase overhead due to context swapping
ideally you should have core count -1 shards
@quartz kindle you mean clusters?
but in the real world nobody uses that because discord shards way too much
@modest maple i mean shards per cpu cores
exactly
and ah yeh
most large bots most likely use anywhere from 2-16 shards per core lol
the most efficient ones will use a combination of internal sharding with processes
client.emojis.get doesnt work
What version are you using?
v12
you need da cache
yup
Not 100% sure, still running 11.1.1 for myself.
Since I don't wanna transition and have to move again with all the new bot stuff in the future.
So whilst it's stable I'll leave my code.
not working for me
i have const tick = client.emojis.cache.get("id")
and then in my message i have
${tick}
Thank you very much tim!
But if less shards is good for performance, why is it generally sharded into 1000 guild per shard? why not exploit the process and use the (almost) full 2500?
@royal portal What is the actual message line code.
if (command === "restart") {
const tick = client.emojis.cache.get("661900429432455187");
const embed = new Discord.MessageEmbed()
.setDescription(`${tick} Restarted.`)
.setColor(0x00AE86)
are you sending the embed?
Tim, how does one use internal sharding with discord.js?
it just sends undefined
@viral spade for growth management, more time without having to restart to change the shard number. also large bots require shard number to be multiples of 16
i have an issue with embeds right now, where on android the mentioned users are invalid users, but when i look it up on my pc, the usernames show up
@cinder patio define the shards you wish to run in the client options (v12 only)
Tim would I use var instead of const
are you mentioning them as <@id> or <@!id> ?
<@id> i think
you could try the other variant, but the result will most likely be the same
You see whatevers cached
@royal portal var or const has nothing to do with it
if you're getting an undefined emoji, then the emoji was not found
but the emoji works
then what is undefined?
then it was not found
ah nvm, im using discordUser.mention
is your bot in the server where the emoji comes from?
either it works, or its undefined 😄
console.log the emoji before sending the embed to see if it gets the emoji
"nope" means it doesn't get it?
yes it doesnt
Tim, you said larger bots need to be a multiple of 16. may i ask where does this come from?
and should i increase my 25 to 32 shards?
You ideally want 1000 guilds per shard
@royal portal if you are talking about this emoji
then you are using the wrong id
@quartz kindle same result unfortunately
it doesn't matter which mention you use
the user isn't in the client cache
you can't do anything about it
oh i see. thanks
yes that's the id, but in your code you posted you used a different one
i tried both
Are we allowed to ask for help
Check the Channel topic.
if(message.content.startsWith(`${p}mute`)) {
if(!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You do not have manage messages.")
let toMute = message.guild.member(message.mentions.users.first()) || message.guild.member(args[0]);
if(!toMute) return message.channel.sendMessage("You didn't specify a user!");
if(toMute.id === message.author.id) return message.channel.sendMessage("You can't mute yourself.");
if(toMute.roles.highest.position >= message.member.roles.highest.position) return message.channel.sendMessage("You cannot mute a member that has a higher or same role as you.")
let role = message.guild.roles.cache.find(r => r.name === "FrontierMuted");
if(!role) {
try {
role = await message.guild.roles.create({
name: "FrontierMuted",
color: "#000000",
permissions: []
});
message.guild.channels.cache.forEach(async (channel, id) => {
await channel.overwritePermissions([
{
id: message.author.id,
deny: ['SEND_MESSAGES', `ADD_REACTIONS`],
},
], 'Needed to change permissions');
})
} catch(e) {
console.log(e.stack)
}
}
if(toMute.roles.cache.has(role.id)) return message.channel.send("This member is already muted!")
await toMute.roles.add(role);
message.channel.send("I have muted them.")
return;
}
So for this command
For some reason
It just creates a new role
And adds it
But it doesn’t do anything
can you add js to the first row, so its "```js"
can you console.log(role) right after the let role = ... and tell me what it says?
Hello im trying to list all users my bot want to list**, but the problem is im just doing a for each users :
newclient.users.cache.array().forEach((member) => {})
So i can't check if the user that i DM is administrator, i would like to do
For each Guild -> For each member, then i can check informations about the user from the server
you should probably use a for loop instead of forEach, as the above code will likely get you rate limited
@earnest phoenix you want to see who are guild administrators?
just dont
you should not mass DM people
I suggest you create a separate channel and mention everyone there instead of mass DMing
shiv u a trialist lmao
its about 15 members 😂
that's a mass dm
"i want to dm all"
"im not mass dm'ing"
But you are still sending multiple DMs at once 
if its a command executed by the server owner to DM server admins, should be fine i guess
Well consent or not, I mean...
you can have 200 admins and you'll be sending DMs to all of them 
but only admins inside that guild
if people are not in your support server they are likely not interested in the news?
rate limit
@slender thistle then u should think about checking ur server admins
U can't get rate limited for 30 dms
Also it will have a cool down
Im obviously not that stupid
yes
Don't want to send 35dm per seconds
I suggest you play it safe tbf
why would you want to dm all admins anyway?
just create a new channel lol
5/5 per channel, not sure how's with dms, since each dm is a different channel
thats what servers are for
Its about my projct, elsei would just create a new channel obviously its not what i asked 
anyway
i still dont understand your project of dm'ing all of your server mods
you can loop over guild members, and check if they have admin permissions
that would require server members intent
yeah i know but i didn't used discordjs for a long time and v12 changed everything, so i don't know how to foreach guild members
https://oliy.is-just-a.dev/92snq_3550.png used to be this, I think it was changed tho
as that is old
thats old tho
but used to be
im pretty sure the 5/5 is now per channel, not per server
let admins = guild.members.cache.filter(member => member.hasPermission("ADMINISTRATOR"))
@earnest phoenix
will only work for online/cached members anyway
Why only online ?
I didn't understand also the cached thing 😉
Can u explain me that as ur here
probably cause member intents?
not all members are cached
if a guild has 200k members, your bot will not have 200k members cached by default, because it uses too much memory
guilds cache online members and active members
oor, you could manually add administrators to a list, and dm that list
I mean the Tim method looks fine
non-cached members are not listed anywhere in your bot program and are not accessible directly
offline/uncached members have to be explicitly requested by using guild.members.fetch(id)
how many times I am allowed to change my bot's activity per minute?
5
well, if all your moderators are offline, that means noone will get the message right?
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
@earnest phoenix caching means storing a temporary copy to make things faster and more efficient
so when discord sends you a message, it also sends you the information of the user/member who send the message
discord.js then caches this information, it stores the user and member data
for later use
does discord also cache invisible users too?
and keeps this data updated, so you dont need to ask discord for this data
@turbid bough probably not because would make able developpers to like
If offline member is in cache
then he is in invisible
would fuck the point of the invisible mode 😂
@turbid bough it caches users that make any kind of activity
if you receive a piece of data that contains some user information, that user will be cached
aight, thats cool to know
I see so if i use non caching method, it won't affect that much my program ? My server wont be scared of that 😂
all methods that are in .cache interact with the cache, which is the local copy of things your program is storing
interacting with those has no rate limits and is very fast
since its all inside the program
anything else that is not in the cache, such as fetching members/users/messages, goes through the discord server, which implies rate limits
newclient.guilds.cache.array().forEach((guild) => {
guild.members.cache.array().forEach((member) => {
})
})
Is this using all members on the servers ?
Or its cached ?
Yeah im stupid its cached lol
"cache" as said im so stupid
cache
soo, since im using c#, i dont really see any cache variables
i wonder if it does that automaticly
different libraries use different names and storage designs
most likely it does have some sort of caching
Tim so do you have the exact alternative as i have to not have caching and then being able to contact all server administrators
Also i can't use filter because i don't only want to check if the user is admin
can you console.log(role) right after the
let role = ...and tell me what it says?
@blazing portal it says undefined
I would like to foreach then execute multiples infios
manually add admins to a list, and pm that list
the only way is to keep your own list of admins stored somewhere
ok, then add them too
then keep your own list for both
what code did you give?
TimAujourd’hui à 20:33
im pretty sure the 5/5 is now per channel, not per server
let admins = guild.members.cache.filter(member => member.hasPermission("ADMINISTRATOR"))
So there is technicly no simple way
yes, that one uses the cache
In discord.js, how to move a category?
setPosition
if (!args[1]) return [utils.timed_msg(utils.cmd_fail(`No guild ID has been mentioned!\n**Usage:** \`${prefix}rem serinv 611809972707131403\``), 5000),];
bot.shard.broadcastEval(`
const servers = this.guilds.cache.get('${args[1]}');
if (servers) {
true;
} else {
false;
} `).then(sentArray => {
if (!sentArray.includes(true)) {
return message.channel.send(' **No guild could be found with that ID!**');
}
const guild = bot.guilds.cache.get(args[1]);
let invitechannels = guild.channels.cache.filter(c => c.permissionsFor(guild.me).has(`CREATE_INSTANT_INVITE`));
if (invitechannels.size < 1) return message.channel.send(' **No Channels found with permissions to create Invite in!**');
invitechannels.random().createInvite(options).then(invite => message.channel.send(`**Found Invite:**\nhttps://discord.gg/${invite.code}`));
});
Is this a working code for a guild in a diffrent shard?
@summer torrent Always thanks
Dont tell me try it ....
It works for the same shard just wanted to know if it would work on a different shard?
broadcastEval evaluates a code or function on all shards
So this will be a 100% for a server on a different shard?
yes
no it will not work
👀
const guild = bot.guilds.cache.get(args[1]); will not exist in the current shard if it exists in another shard
👀
i believe i told you before, you need to create the invite inside the broadcastEval
and return the invite code
What means <Array<*>>
probably array of values that can be of any type
When I do this ...
if (!args[1]) return [utils.timed_msg(utils.cmd_fail(`No guild ID has been mentioned!\n**Usage:** \`${prefix}rem serinv 611809972707131403\``), 5000),];
bot.shard.broadcastEval(`
const servers = this.guilds.cache.get('${args[1]}');
if (servers) {
let invitechannels = guild.channels.cache.filter(c => c.permissionsFor(guild.me).has('CREATE_INSTANT_INVITE'));
if (invitechannels.size < 1) return message.channel.send(' **No Channels found with permissions to create Invite in!**');
invitechannels.random().createInvite(options).then(invite => message.channel.send('**Found Invite:**\nhttps://discord.gg/${invite.code}'));
true;
} else {
false;
} `).then(sentArray => {
if (!sentArray.includes(true)) {
return message.channel.send(' **No guild could be found with that ID!**');
}
return;
});```
Tells me invite not defined
To get an invite for an x server
this is precisely why I don't allow bots to have invite generation
Well mine i am working on a bump bot
i was writing a sample piece of code for you, and i found out another problem
does broadcastEval even support promises?
i dont think so
(node:15) UnhandledPromiseRejectionWarning: RangeError: Invalid permission string or number.
at Function.resolve (/home/container/node_modules/discord.js/src/util/Permissions.js:195:65)
at RESTMethods.createGuildRole (/home/container/node_modules/discord.js/src/client/rest/RESTMethods.js:438:58)
at Guild.createRole (/home/container/node_modules/discord.js/src/structures/Guild.js:1152:37)
at Object.execute (/home/container/commands/Moderation/muterole.js:38:32)
at Client.<anonymous> (/home/container/index.js:132:13)
at Client.emit (events.js:323:22)
at MessageCreateHandler.handle (/home/container/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/home/container/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (/home/container/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/home/container/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
(node:15) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I got this error with this code:
const success = new Discord.RichEmbed()
.setTitle(':white_check_mark:')
.setDescription('Successfully made a role named Muted.')
.setColor('#00ff00');
if(!message.guild.me.hasPermission("MANAGE_ROLES_OR_PERMISSIONS")){
return message.channel.send(nobotMR).then(m=>m.delete(10 * 1000));
}
if(!message.member.hasPermission("MANAGE_ROLES_OR_PERMISSIONS")){
return message.channel.send(nouserMR).then(m=>m.delete(10 * 1000));
}
if(message.guild.roles.find("name","Muted")){
return message.channel.send(alreadyarole).then(m=>m.delete(10 * 1000));
}
var rl = message.guild.createRole({ name: 'Muted', permissions:{
"SEND_MESSAGES": false
}}).then(
message.channel.send(success).then(m=>m.delete(10 * 1000))
);
message.guild.channels.forEach(c=>{
channel.overwritePermissions(rl, { SEND_MESSAGES: false });
})
I tried changing SEND_MESSAGES to a string but I got the same error. How should I go about fixing this?
MANAGE_ROLES_OR_PERMISSIONS is not a permission flag
damn, you beat me to it
@heavy marsh i guess it does then, interesting




