#development
1 messages ยท Page 941 of 1
wait
wait
if you disable presence intent, you wont recieve guild members on guild joins, right?
isnt presence only for user activity? like, their current game and status? why would that be relating to guilds at all? seems silly imo ๐
could be tho idk
yeah you'd think that
but not subbing to presence intent actually affects quite alot of things
:/
Presence basically gives you all user info updates
Your member cache is usually outdated without presence, since the bot won't recieve information about users changing their name
Also TheNoob27, the guild_members intent is tied to those events
So those events should be called if you have the guild members intent
wait, so if i dont enable those presences, and i - for example - try to show an embed with a member.username it could* display the old incorrect name?
Potentially, unless you make a call to discord to retrieve the users info
lmao wth
Presence gives you all info on user state changes, which includes user info changes ยฏ\_(ใ)_/ยฏ
It always has the most up-to-date data
usernames tho ๐
like, every bot i would imagine uses a username somehow
for discord to add an intent that will make usernames not be accurate is a joke imo
like, thats the one thing that has to be up to date imo
Just retrieve the new user info
anything else, sure, fetch the data, but a username should be updated with every ping or w.e
perhaps not every ping
but yea.
I mean, if you are using the member who sent the message then yeah their data will be up to date
Since the message contains the member instance
I meant if you are grabbing a random user from the member cache, there's no guarantee their info is up to date
yea thats what i mean. i dont mean like, some other members username, but the member who is using the bots commands
ahh yea, mkk thats fair then lol
Oh, the member using the command should be up-to-date
i had a panik mode there for a minute cause i recently decided to remove anything that required intents lol
@vivid crescent can i send you some code because i am getting an error saying ReferenceError: bot is not defined
Send the full error + code here
^
thats what this channel is for anyways
yeah ig
its also better to not request assistance from a specific person as it may limit the people who reply to you. imo
facts
const Discord = require("discord.js");
const Bot = new Discord.Client();
const token = 'Hidden';
bot.on('ready', () =>{
console.log('This Bot is Active');
})
bot.on('Message', msg=>{
if (msg.content === "HELLO" ){
msg.reply("HELLO FRIEND!!!");
}
})
bot.login(token);
Bot not bot ^^
man im dumb thanks for the help
np ๐
Np lol
programming is always case sensitive, its always best to make sure your using correct spellings and case ๐
which is why you will sometimes see stuff like
let Client = Discord.Client;
let client = new Client();
Do events need to be lowercase as well? Will that message event work?
i think javascript is case sensitive all the time so ig
I don't use djs ยฏ\_(ใ)_/ยฏ
same i switched to eris
seems they have whats it? camel case? for some events
camel case with a lower case intiial letter?
lowercamelcase
idk what thats called lol
Called lower camel case ๐
fair enough ๐
damn thats all it need
?
im am dumb thanks for the help also
It's ok, we all start somewhere
no ur not dumb, ur just starting
^
i've been coding idk, like 8-9 years? and still do dumb shit every day.
anybody willing to try help me with this weird vue/sass error
https://cdn.discordapp.com/attachments/385837258768515083/713939383824154694/unknown.png
Got an empty selector?
idk any vue or sass ๐
in discord.py i have a command that i want to reply to your message when you do b!info but i keep getting error messages. can someone help with how to get it to send these messages in response to the command?
can barely get by with regular css ๐
nope i got it nvm
@earnest phoenix renders pages on the front end not the back end
so page changes are instant for eg
thx
oh thanks, im a bit confused by the usage, could you give an example please?@vivid crescent
which of these should i do for something like loading a list of blog posts
Fetching After Navigation: perform the navigation first, and fetch data in the incoming component's lifecycle hook. Display a loading state while data is being fetched.
Fetching Before Navigation: Fetch data before navigation in the route enter guard, and perform the navigation after data has been fetched.```
why are you making a bot send so many messages for one command devin? wont that be api abuse?
bot.send("line1\nline2")
Yeah
should i show the page and then display the posts , or only show the page when done
Like that
okay thanks, sorry im new to coding, i have commands that work but they all rely on message.content.startswith and im trying to change them all to actual commands
Quantum you can show the page with a loading icon ยฏ\_(ใ)_/ยฏ
^
page load faster, data load after, show loading icon in meantime.
whenever i show posts i have a modal window appear with a loading icon in it and then that window displays the data.
^discuss also does the same
disqus*
i dont see where the error is??
https://dbl.is-stinky.wtf/xgizrouuwv.png theres your error probably
you're missing the n for the line break presumably
yeah dont use ' inbetween these i think
a line break should be a part of the actual string
Need to join your strings
my ping command doesnt even work, is it the bot.send('pong') that is wrong??
sorry for asking so many questions, i just dont know why it isnt working
also, is that a . at the end of your line in between ' and ) ?
yeah it was, i fixed it and the error still showed up
im not sure but i might need to update. ill do that now
so i got my code to work but it for some reason will not work When i try to use the command i set
@bot.command()
async def test(ctx, *, arg):
await ctx.send(arg)
is it not self-explanatory?
You need await
hm thats not what the tutorial showed at all lol
jesus christ im an idiot, thank you
Role mentions in embeds don't trigger the mention right?
unless the mention is on the actual message above the embed, then that user/role will get mentioned
So in the fields its fine
yeah
anyone know
why this dosent work
const { RichEmbed } = require("discord.js");
var servers = {};
const ytdl = require("ytdl-core");
module.exports = {
config: {
name: "play",
description: "play a song",
aliases: ["p", "pplay"]
},
run: async (bot, message, args) => {
message.channel.send("this is the start of the command")
let premium = bot.db.get(`premium_${message.guild.id}`)
if(!premium) message.reply("sorry! This server doesn't own premium! Buy it today!")
if(premium) {
function play(connection, message) {
var server = servers[message.guild.id];
server.dispatcher = connection.playStream(
ytdl(server.queue[0], { filter: "audioonly" })
);
server.queue.shift();
server.dispatcher.on("end", function() {
if (server.queue[0]) {
play(connection, message);
} else {
connection.disconnect();
}
});
if (!args[0]) return message.reply("sorry. I need a link!")
if (!message.member.voiceChannel) return message.reply("join a voice channel!")
if (!servers[message.guild.id])
servers[message.guild.id] = {
queue: []
};
var server = servers[message.guild.id];
server.queue.push(args[0]);
if (!message.guild.voiceConnection)
message.member.voiceChannel.join().then(function(connection) {
play(connection, message);
let embed = new RichEmbed()
.setColor('RED')
.setDescription(`๐ถ Now playing ${args[0]}.`)
.setFooter(bot.user.username, bot.user.displayAvatarURL)
.setThumbnail(bot.user.displayAvatarURL)
message.channel.send(embed)
});
}
}
message.channel.send("this is the end")
}
}
it shows the "start of the command" and "end"
but nothing else
I can work it out to prevent bots from getting xp??
just check if the user is a bot or not
@astral yoke ill go through it in a sec
how can i do that?
if (message.author.bot) return;
where?
if possible in every condition check
Im wondering if there is a way to run code from a command you type in discord... Is it possible?
yeah
a bunch of bots have repl commands
if you use js or python iirc it's not hard to add one
Ok, I have no idea where to start to make that command. I would love help!
Sorry if it sounds a little rude, i was trying to think of a way to say it without making it sound like that, im using discord.js
yeah
i haven't done any of this stuff in a while as my bot i'm currently working on is made with a compiled lang
๐
evals are for noobs, hardcoding it and recompiling is for pros 
I made a command to make a command because I'm lazy
i made a command that autoclones from github, and start the bot with the new code
i could just start up a docker container containing the eval bot and then close it when it's done
const applyText = (canvas, text) => {
const ctx = canvas.getContext('2d');
// Declare a base size of the font
let fontSize = 70;
do {
// Assign the font to the context and decrement it so it can be measured again
ctx.font = `${fontSize -= 10}px sans-serif`;
// Compare pixel width of the text to the canvas minus the approximate avatar size
} while (ctx.measureText(text).width > canvas.width - 300);
// Return the result to use in the actual canvas
return ctx.font;
};
client.on('guildMemberAdd', async member => {
const channel = member.guild.channels.find(channel => channel.name === 'welcome');
if (!channel) return;
const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext('2d');
const background = await Canvas.loadImage('./wallpaper.jpg');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
ctx.strokeStyle = '#74037b';
ctx.strokeRect(0, 0, canvas.width, canvas.height);
// Slightly smaller text placed above the member's display name
ctx.font = '28px sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText('Welcome to the server,', canvas.width / 2.5, canvas.height / 3.5);
// Add an exclamation point here and below
ctx.font = applyText(canvas, `${member.displayName}!`);
ctx.fillStyle = '#ffffff';
ctx.fillText(`${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);
ctx.beginPath();
ctx.arc(125, 125, 100, 0, Math.PI * 2, true);
ctx.closePath();
ctx.clip();
const avatar = await Canvas.loadImage(member.user.displayAvatarURL({ format: 'jpg' }));
ctx.drawImage(avatar, 25, 25, 200, 200);
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');
channel.send(`Welcome to the server, ${member}!`, attachment);
});```
Hey everyone! this is my code and the error is member.user.displayAvatarURL is not a function
๐ Thanks in advance
welcome message?
that cant be the error
yep welcome message
hello
that cant be the error
@grizzled raven https://valckyz.is-inside.me/4DOfjyKo.png
Can anyone help?
theres no such thing as display avatar url
oh thx hope!
message.member.setNickname("") would reset the nickname right?
yeah
thanks
theres no such thing as display avatar url
@earnest phoenix What can i put so that i get the person's avatar?
literally what i've sent
or whats the error now?
OwO in #memes-and-media 
can anyone help me figure out why this is just now happening
this just started happening with everything i code
you are lmao
omg i am so sorry
big brain
@spice pasture you having quite the big developer stroke right there
WAIT WHAT
AHAHAHAA
ok
im not insane
ok
i swear
my ise
ide
just
i must have accidentally switched it to python

hmm no
its still crashing when i run it with the debugger
wait
im just dumb
python debuggeer
.>
make sure the debugger is js, not python

welcome to the frustrating world of development
yeah ive been developing for two years
wait three now
my last "wtf" moment was
plotly crashes pm2

I mean
if you read the error
it's a python error
and the way the traceback looks
you know it's python when you see it
it's 11:14
ok cool im not insane
get some sleep before you ask yourself why your bot is not running, try to debug it for 5 hours and realize you didnt even start it
I'm insane tho
the (javascript) debugger is crashing on perfectly fine code still
lol
i speak from experience 
ok the debugger was not crashing
the program was exiting normally because 50507 =\= 5057
I saw that ping 
yeah lul I was behind
you gotta be faster
I thought the messge he sent was like posted now lmao
but nope it was like idk ages ago
How do you find how many bots are in a server? i use discord.js
iterate over the members of that server, and check if the user is a bot.
Ok so the debugger is still closing but turns out that's because minecraft is rate limiting me
Annoying
make sure its not python again
Suddenly realizes he accidentally started coding a minecraft plugin instead of his bot
lmao
so i got that error when my bot went to a new server and i tried to interact with it, because it didnt have permissions, obviously.
however, i check if i have relevant permissions before sending anything
what permissions other than 'SEND_MESSAGES' would a bot require in order to send a message?
maybe embeds?
yea im going through each permission atm to see which one it is that is needed
is there any way I can get the permission integer of a role?
'embed links' permission seems to fix it
thats my embed, which doesnt actually link anything
so it must require that perm just to add an embed
@tall arrow depends on what library
discord.js
You can have role permissions by doing <role>.permissions
Pretty sure you can find what you want
le me try
so ill have to update almost all my commands to check for that permission also lol
thats dumb
No
d.js v12 @tall arrow?
ye
yes, thats what i do, but each command has an array containing the permissions it requires to be used.
I personally do that in the command itself
so ill need to update that array with this perm, so that the message event will correctly check for it
easy enough change tbh ๐
just tedious
If I'm not wrong, its over here: https://discord.js.org/#/docs/main/stable/class/Permissions?scrollTo=bitfield
You just need to do role.permissions.bitfield @tall arrow
thanks,that was usefull
How do you find how many bots are in a server using discord.js?
check the docs and try to get what you think should be the correct code
can't be expecting people to spoonfeed
@wheat valve someone told you already
and ask here for help with your current code
iterate over the members of that server, and check if the user is a bot.
Me and him had a conversation in DMs and it didn't work
that can still work
just loop through the users and check if these users are bots
show what you current have so far
-
https://discord.js.org/#/docs/main/stable/class/GuildMemberManager?scrollTo=cache
-
https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=filter
-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size
Have a read.
the general concept is that you should have a loop to iterate through the users of a guild and get those that are a bot
The code I have, if you look in #265156322012561408 in shows "0" has the bot count
let args = message.content.substring(PREFIX.length).split(" ");
switch (args[0]) {
case 'serverinfo':
if (message.author.bot) return; // do nothing
if (!message.content.startsWith('RH-')) return;
const bot = message.guild.members.cache.filter((u) => u && u.bot);
const serverinfo = new Discord.MessageEmbed()
.setColor("#0099ff")
.setTitle('Server Information')
.setThumbnail(message.guild.iconURL())
.addField('Server Name:', message.guild.name, true)
.addField('Server ID:', message.guild.id, true)
.addField('Server Owner', message.guild.owner, true)
.addField('Role Count:', message.guild.roles.cache.size, true)
.addField('Member Count:', message.guild.memberCount, true)
.addField('Bot Count:', bot.size, true)
.setFooter(message.guild.name)
message.channel.send(serverinfo)
break;
}
})```
Thanks!
ClientUser ah, yes
i just look at the docs okay 
tbh that was my bad for totally blanking that bot was a user prop and not a member one ๐
hi
if i have {+role:role} how can i search for that? i done js const array = ['h', 'e', '{+role:role}']; array.find((e) => 'e' === e) so, what can i do to get {+role:role} from that? i can't look for the exact match cuz idk what the role they want 2 add is.
battleships is a harder game than i thought ๐ข
if (args[0] == "true") {
if (log[message.guild.id].logs == "true") return message.channel.send("You already enabled logs");
log[message.guild.id] = {
logs: args[0]
}
writeFile("./logs.json", JSON.stringify(log), (e) => {
if (e) console.log(e);
});
let embed = new RichEmbed()
.setColor("RANDOM")
.setTitle("Enabled logs")
.setAuthor(message.author.username)
.addField("**Date:**", message.createdAt.toLocaleString())
message.channel.send("Enabled logs");
let sChannel = message.guild.channels.find(c => c.name === "logs")
if (!sChannel) {
embed.setDesctiption("Generated Logs channel");
}
if (sChannel) {
sChannel.send(embed);
}
}
and the stringfy making the json file error
{"701141875628834906":{"logs":"true"}}}
3 } at the End of the Json file
idk why
w/o the u adding data to the json
it was
{"701141875628834906":{"logs":"fasle"}}
no i mean
when u created ur json file
what did it look like
u just done js { } or something?
yes
it was {}
message.js : https://hastebin.com/ovawasidov.js
logs.js : https://hastebin.com/xuvobimapi.js
Why are you using JSON as a database? I did that too but MySQL or something like that is way easier and better
json is actually easier but it's unreliable and slow
well for me mysql is easier. You can easily get a time difference or something, and you don't have to loop through it to find elements
dude
I just asked a simple question but okay, won't help you then ๐
okay does the console give an error?
nah
or is it an error according to you?
your json file should not be an object containing objects which is what it seems like you have done.
i mean, if your empty file contains {} and your reading from that file, and then adding to that data, and then saving it with stringify, it should be fine
I think the third } is because the json file ends there
the file was {} and i use code to chnage the file
but if your like, trying to save something like {{"thing":{'a':2}}} then that probly wont work
wut
{{"701141875628834906":{"logs":"fasle"}}}
come i will screenshare
is what it looks like your trying to save
the file was so :
{{"701141875628834906":{"logs":"fasle"}}
after /logs true commands
{{"701141875628834906":{"logs":"true"}}}
message.js : https://hastebin.com/ovawasidov.js
logs.js : https://hastebin.com/xuvobimapi.js
thats what i mean though
you have an object within an object
{{"701141875628834906":{"logs":"fasle"}}
so how i can fix it
remove {}
wut
just let the file be empty
so it will give error
but i want it automaticly
let the file be {}
make it js log[message.guild.id] = args[0];
tbh you should be using a proper database for guild configurable options as when saving a file, if your bot dies,. your file is rekt
and if that file has the config for all of your guilds, thats catastrophic
-______-
backups :^)
also, good practice for json files is to save to temp file then rename file
instead of saving directly to file
just because you can doesn't mean you should, proper databases exist for a reason. there's also a reason why none of the successful bots use json files as their storage
ok
but i cant use database
sounds like a you problem
i got to 2500 guild running on json lmao
but yeah, dont do that pls
i deeply regret it
it's probably slow though
it wasnt slow at all actually
oh
because it was done properly
memory caching ig
ye
from your code it looks fine, i dont get what could be causing it
you can fix it but you'll ended up having to switch to an actual database later so why not now
man, when i was first researching discord bot examples, everyone seemed to use some json storage module thing that i cannot find at all now lol
we can't fix it if the root if the issue is the thing that you're actually using
@neat ingot probably configs, not dbs?
ikr
but it could be helpful if dude is really determined not to database
although, databasing is ez af
then use other host
everyone used to use enmap no?
enmap yes!
now everyone uses quick.db
omg, ty tim
postgres is available on heroku too
Better-sqlite
two trash means of storing data.
but they are much easier than setting up an actual worthwhile database
lol
tbh no one should be using that for data intensive things anyway
How to make top gg show the number of servers in discord.js
send the data from your bot to top gg servers via dbl api (js) or equivalent
https://dbl.marcorennmaus.de/ranking/servers
rank by servers i mean, you can rank by votes as well
in profane filter github saying to module.exports = require("./words.json") {at the index.js} but seemsly it doesn't work after doing all of the instruction.
oh i aint gonna be anywhere near the top 1k lol
@earnest phoenix check the official libraries section
okay
11 votes this month ~ thats rough! need to vote lock your commands tim ๐
nah fork that
lmao
im vote locking some commands for my new minigamebot
like, it costs credits to play, credits from voting, easy enough.
I can't find the official libraries section
got a decent list of dumb games already ๐
all of them technically vote locked from the credits thing.
@earnest phoenix
Anyone can tell me, wut the heck is shard
technically, a discord connection
ok . . . . (i dont understand)
often used to refer to a bot process in a large multi-process bot
oh
when you reach 2500 servers, discord forces you to start sharding
which is splitting your bot's connection into multiple connections
oh
i thought it was at 2k?
oh
each connection handling a part of the total servers
isnt it cause of websocket limitations?
you don't need it
you can shard at any point
you can use it, but there is no need until you have many guilds
but i dont need it
but you only need it at 2500
ok
module.exports = (error, description) => {
switch (error) {ย ย
caseย "CoolDown":
let cooldown = `Please Wait \`${description}\` More Second(s) Before You Use This Command`
return cooldown;
ย ย ย ย break;
}
}
wut is the problem
I need string
isn't it
error
box-shadow in your css
make sure to use !important
Ok wtf kind of permissions do you need to create an overwrite for a channel?
In discord.js
MANAGE_CHANNELS
It doesn't work @pale vessel
I tried it multiple times
okay
The bot has manage_channels yet it gives me a missing permissions for every channel I try to change perms in
Is this for discord.js?
Or for python
kk
I ll take ss and try later
But thanks man
It does
@pale vessel
caseย "CoolDown":
let cooldown = `Please Wait \`${description}\` More Second(s) Before You Use This Command`
return cooldown;
ย ย ย ย break;
}```
How can I get this output in event
did you try to change client.emit('errors') to error
No
how to delete messages by userid
It has MANAGE_CHANNELS but still gives the error vor every channel, when I give it admin perms it works though
djs
you can get messages and filter the author and delete them
how to get messages, i tried a few examples but none worked lol
read docs
search mongodb @earnest phoenix
cuz there is a lots of mongo
On the role but I've tried with .filter(channel => channel.permissionsFor(message.guild.me).has("MANAGE_CHANNELS")) and that didn't work either @low orbit
i have mongo uwu
use mongoose. its a node js module for managing mongodb
Yhea
@neat ingot wait the nodejs will auto host a localhost server, when i use mongoDb ??
no?
although it could
watch more than 1!
watch like, 5-10
that way you wont come asking dumb questions about it later ๐
that seemed meaner than i intended, sorry ๐
LMAO
mongodb+mongoose is also what i use. i swear by it โค๏ธ
Anyone know what's up with my bot having MANAGE_CHANNELS yet not being able to change perms?
@neat ingot suggest for mongo version
Wait lol
wouldnt it need MANAGE_ROLES or something for that? I had an issue earlier where I found out embeds wouldnt send without the 'embed links' permission :/
I was iterating over it with an array but if I iterate over it with in it works
@low orbit Best way to do it is use element inspect and click this
That's extremely weird
idk even what mongo version i use atm lol
lol
Or wait it doesn't even
Did you try background: transparent !important; ?
@low orbit inspect element is your friend
@neat ingot mongo is a shell app
it has no UI ??
rly
correct. you would use some other ui, such as 'mongo admin' or one of the countless others.
also, yes, mongodb would run a localhost server on your machine on port 27017 or something by default
but node js would not
i dont think ive ever used mongo via command terminal ๐
been using it for like, 4 years or so
Anyone know of permissions needed to create overwrites that isn't MANAGE_CHANNELS?
Wow thanks
Read the discord api documentation
It's manage roles
Integrate your service with Discord โ whether it's a bot or a game or whatever your wildest imagination can come up with.
as i said, pretty sure it was manage roles.
That's so stupid
I missed your message damn @neat ingot
Thx
So stupid that it needs that perm
yea lol
i think its also stupid that you need embed links perm to send an embedded message without a link ๐
like, regular discord embed object
Lol
Hello. Can someone help me out here? In line 421 my bot says: TypeError: 'bool' object is not subscriptable and I do no know where I did somethin wrong...
https://stackoverflow.com/questions/44337101/typeerror-bool-object-is-not-subscriptable-python-3 reading this might help you
I was on that site and the code is totally different/faces other things I do not use in my code
You know what is the permissions to send embed ?
Ty
so my bot has a feature where it fetches information based on text between curly shits, {like this}. for this im using the regex /\{[^}]+}/g to get the text between the curly shits. a small problem with this is that it triggers in codeblocks too, and i have about 0 idea how to fix it
How can i run my bot 24/7 without heroku
no
buying a vps is worth it
How much is a VPS?
considering it's windows xp it's probably a bad idea
XP is out of support for 6 years now so its possible that the required programs dont even run anymore
Hi I am trying to use shoukaku, and I am not entirely sure how to set the bot to be deaf, and I couldn't find it in the docs, can someone help
Support server
Did you see the 3 codes to enter on MongoDB to get 500$ ? ๐ค
NRABOY200
GETATLAS
WF200
its for mongo atlas specifically
useless to most unless u somehow cant host urself
Support server
@zenith terrace thanks what would I do without you
Lol
by using css
and inspect element
we aint
here
thats what inspect element is useful for
^
Hi I am trying to use shoukaku, and I am not entirely sure how to set the bot to be deaf, and I couldn't find it in the docs, can someone help me out or link me to the page on the docs (I asked in the support server and they didn't respond)
so my bot has a feature where it fetches information based on text between curly shits, {like this}. for this im using the regex
/\{[^}]+}/gto get the text between the curly shits. a small problem with this is that it triggers in codeblocks too, and i have about 0 idea how to fix it
@mossy vine pretty sure you gotta just get rid of codeblocks before tryna parse curly braces
how do you host a bot with heorkuu
Upload it to GitHub and add a procfile
help please
const Discord = require("discord.js");
const ms = require("ms");
module.exports.run = async (bot, message, args) => {
//!tempmute @user 1s/m/h/d
let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if(!tomute) return message.reply(" \`!!mute <@USER> <1sn/1dk/1sa/1g>\`");
//end of create role
let mutetime = args[1]
.replace(`sn`, `s`)
.replace(`dk`, `m`)
.replace(`sa`, `h`)
.replace(`g`, `d`)
if(!mutetime) return message.reply(`:warning: Time? \`!!mute <@kullanฤฑcฤฑ> <1sn/1dk/1sa/1g>\``)
await(message.guild.channels.get(`${message.guild.id}`).overwritePermissions(tomute, {
SEND_MESSAGES: false,
// VIEW_CHANNEL: true
}))
// await(tomute.addRole(muterole.id));```
you're trying to get the channel from the message id it seems like
correct me if im wrong
@toxic jolt i told you whats wrong, you're trying to get the channel through the Message ID seen by ${message.guild.id}
but im pretty sure the {message.guild.id} returned undefined because obviously theres no channel with that "message ID"
"discord.js": "^11.5.1",
noo :(,
can someone help me on caching data to the client from a database?
if I upgrade it will give a lot of error.
that's okay. you can fix them. if you're on v11 until the next few months, you can't fix the errors without upgrading
When caching db rows into the client on cache miss, what do i do with other cache misses, while the first one is still loading?
if they depend on each other, fetch them sequentially
if they are independent, fetch them concurrently
lets say i want to cache guild information. So add guild.appData.prefix, ..
The getGuildCache function that impelemnts the cache miss will be called from all kinds of events "at the same time".
so its no independent or dependent, its the same information
(thank god youre here tim)
ah i see the issue
we should all chip in $1 each and order tim a superman costume with a big T logo on it ๐
no no idc how well you eat! i care about fashionable skin tight outfits ^_^
so basically a deferred promise (idk if that's even the name for it) works like this
i will store the promise in a loadingGuilds map?
and place it "onto" the new call somehow?
so when the promise resolves it will send the result to all instances?
let promises = {}
getGuildCache();
getGuildCache();
function getGuildCache(id) {
if(!client.guilds.get(id).AppData) {
if(promises[id]) { return promises[id]; }
promises[id] = new Promise(async resolve => {
data = await db.guilds.fetch(id) // or whatever your database does
client.guilds.get(id).AppData = data;
resolve();
});
return promises[id];
}
}
when a concurrent call happens, it checks if there is already a promise waiting, and if it does, return the existing promise instead of creating a new one
oh man tim thats like a so fine solution to a problem i have been thinking on quite some time now.. i will try, thank you so much
then you can await getGuildCache() once the promise resolves, all concurrent operations will proceed
discord.js version?
overwritePermissions takes a list of overwrites
and replaces all overwrites with it
if you want to update a single overwrite, use this
that only updates the permissions on one channel
yes
overwritePermissions also only updates one channel
there is no method to update all channels
you need to update them one by one
YES, I finally won a game โค๏ธ
@neat ingot is that battleship
yup ๐
noice
haha cool
one of my 9 finished discord games ๐
so this should do it for each?
no
annoying though cause my mobile cant display all the emojis for monopoly ๐
using a forEach for api calls is a bad idea, because that will make your bot send all updates at once
and will likely get rate limited by discord
you should use a for loop and await each call
for(let [id,channel] of message.guild.channels.cache) {
await channel.updateOverwrite(...)
}
tim, does the caching code you posted allow null values to be resolved/cached? or will your db always insert on a miss (most importantly for the guildmember cache)?
i was thinking about setting up a default object that gets used if it was not found in the database. and then only actually insert when a set happens
if you do resolve(null) the promise will return null to the variable that awaited it
if you do resolve() or resolve(undefined) it will return undefined
so you can do let data = await getGuild(); if(!data) { insert default data }
sure, i just mean in general do you assume the getCache call will have xsuccessfully cached all values so these settings can be accessed
you can do the same in your await fetchFromDb thing
inside the function
if the db fetches, add it to guild, if the fetch returns nothing, add a default to the guild, then resolve the promise
i know, but i was thinking about not inserting a row that has not changed its default values
for example. looking at the guildChannel entity, i have the property noxp (no xp channels).
If i make the insert-on-db-miss for every channel, where a user writes, i have a lot of channels in the db. BUT i could also only insert the channels, where the admin changed the noxp value and if the db calls returns 0 rows, i will simply put a default row at its place for the cache.
for inserting to the db its another story
if you're going the write-in-chunks route to reduce db writes, you can save an object of db changes somewhere
for example, channel A was changed, store somewhere that channel A was changed, then when the insert to db function gets called, it inserts only the data that was changed, and then reset the was changed state
alternatively, once a channel changes, immediately write it do the db
i am not sure if were talking about the same thing ๐
I am talking about not inserting most rows at all. about size of the database.
So 100% of all channels need to have the noxp property cached. like 0.1% are noxp channels.
If i "get-insert" every channel i cache i need to have 100% of channels in my database. If i instead only insert when someone changed the noxp setting (and put a default object on the cache if it was not found) i will only need to have 0.1% of channels saved in my db.
well yes, thats a given
you dont even need to give it a default value
just omit it, if it doesnt exist it means its not set
well but i want that the code if(channel.noxp == true) resolve();
to not throw erroes and i also dont want for every property to check all the time if it is set, right?
but whatever, i am wasting your time. i need to try this first. thanks!
why not if(channel.noxp)?
but well, all other values besides 0 would still work
noxp can have only 1/0.
well guildmember is the most easy example, but on guild for example, i need a mix of strings, dates, ints over like 30 necessary setting properties
i mean i could write everywhere f.e.
if(!guild.pointsPerMessage) guild.pointsPerMessage = 3;
But then i would have to write that at multiple locations, for many properties
Discord bots can not send animated or custom emojis?
In discord.js how can I have a command is guild a add a role in guild b
im just gonna go out on a limb here and say you shouldnt be doing that
Are you talking to me?
yea, sorry lol
And why shouldn't I do that?
How?
I don't think your understanding.
The user does something in one server. i.e sets up our bot. then gets a role in our support server
<:name:id>
<a:name:id> for animated
not animated?
there is no guarantee your bot client is in the support server (when sharding is involved)
message.guild.roles.cache.get(roles => roles.delete); not reacting
instead you should setup some kinda webhook event that your support server listens for
v12
delete is a method
v12 js
make it a function
it
well
message.guild.roles.forEach(roles => roles.delete);
not reacting again xd
that's not how it works
dude, your not calling the function.
your just checking if that function exists and then doing nothing with it
what function? v12 not working
also not sure thats even valid lol
The roles.delete part could be really confusing tbh.
read that and learn how to use loops
nothing seems understandable
you also shouldn't use forEach because it would lead to api abuse
to know a little english
i feel like you really need to have at least a basic understanding of english in order to understand docs and guides.
Hello, when I upgraded to discord.js 12 my economy command /top stop working.
Bot must delete user's reactions from message, but bot must'nt remove himself reactions.
In discord.js 11 I do this if(user.id != client.user.id) { reaction.remove(user.id); } but in discord js 12 this remove bot reactions too.
How can I fix it?
that happened to someone else too
i didn't touch reactions when using discord.js so i can't help you, sorry
remove brackets 
Thx
oh, 'this hwnd' in that code reffers to a sent message
hwnd is just the message that was sent.
Ok
i should actually probably change that guild.me.has permission thing cause it doesnt take channel specific perms into account which could cause errors
readable though an understandable guide @pale vessel xd
np ๐
how do i check if a member object is a bot in python?
ight cool
but it will almost 100% always be false
as discord.py Automatically ignores bots if its the commands.Bot
yeah but lil check to ignore bots
my friend was trying to talk me into making a bot that just randomly repeating things back to you
like, it wouldbe quiet for hours, then just copy or repeat a random phrase it had heard throughout the day
hey uh
im trying to make my bot have a status
this isnt working
bot.user.setActivity.('prefix ples', { type: 'STREAMING' })
i dont know what to set it to-
it says
TypeError: Cannot read property 'setActivity' of null
can someone help?
wait until you have connected properly
you are calling this method before you have connected to discord
so the bot user doesnt exist yet
wait do you have to put it after bot.login?
@white anvil it still says null
i dont know have to put it after ive connected to discord
no
Use the ready event
logging in takes time
you are logging in and you are trying to set activity before it has finished
idk how to use the ready event
um
@hasty sparrow what is the ready event and how do i use it-
Here's an example, but I suggest you learn JS first: https://discordjs.guide/creating-your-bot/#logging-in-to-discord
make sure to select v12 on top
You also never set a bot's status before?
no
K
oh i did it
bot.once('ready', () => {
bot.user.setActivity('my prefix ples', { type: 'STREAMING' })
});```
So if you didn't want to restart your bot to change something in an event, how could you do that?
Like is there a way of doing it in the same way in commands?
I'm just not sure if something like this would work
i dont know ive never done this before-
fs.readdir("./events/", (err, files) => {
if (err) console.log(err);
for (const file in files)
let eventFunc = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.events.set(file, {name: eventName, run: eventFunc.run})
};
});
for (const event in client.events){
client.on(event.name, (...args), event.run(...args))
}
make a function that reloads the event
how do i run that function
Ok so like commands, I was just wondering, thanks ๐
oml this is all confusing
i dont know what to put to make a function that reloads the event-
should i?
it's okay for now.
ok
i kinda need it
so i can do it faster than restarting my bot
because right now it takes forever for it to log off then log back on
best to learn some javscript or w.e code language you use first before deciding what you 'need'
hello i am getting some error saying SyntaxError: Unexpected end of input
i only know basic javascript
then learn some not basic javascript ๐
@plain current you have code where it shouldnt be
Like this?
client.reloadEvent = function (eventName) {
delete require.cache[require.resolve("./events/" + eventName)]
client.events.delete(eventName)
const event = require("./events/" + eventName)
client.events.set(eventName, { name: eventName, run: event.run })
}```
explanation 100
ehhh, i wouldnt do it quite like that cx, but it looks functional enough assuming client.events is a discord collection.
It is
ok because i used to get an error saying SyntaxError: Unexpected token and now it is this one
how do i use that @golden condor
you should learn js first @plain current
fs.readdir("./events/", (err, files) => {
if (err) console.log(err);
for (const file in files) {
let eventFunc = require(`./events/${file}`);
client.events.set(file, eventFunc)
let eventName = file.split(".")[0];
client.on(eventName, (...args) => eventFunc.run(client, ...args));
};
});``` Should I do something like this or what I showed before?
i wanna try to use one of those
that would reload all events
fs.readdir("./events/", (err, files) => {
if (err) console.log(err);
for (const file in files)
let eventFunc = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.events.set(file, {name: eventName, run: eventFunc.run})
};
});
for (const event in client.events){
client.on(event.name, (...args), event.run(...args))
}```
thats some very basic stuff right here, you should atleast know a little bit what youre doing @plain current
No I mean before it starts
that would reload all events
@pale vessel Ik that would be on start
then don't say this
Should I do something like this or what I showed before?
but what about reloading, I was wondering about that, would it actually work?
Ok
how do i make an event run when someone joins the server
wasnt it like
guild member add
or something
personally i would create an event handling class, and give it functions for loading/unloading/removing events entirely. i'd then create a dev command that uses that class to load w.e the events.
yea its guildMemberAdd
ok ty
personally i would create an event handling class, and give it functions for loading/unloading/removing events entirely. i'd then create a dev command that uses that class to load w.e the events.
@neat ingot how lol
he literally told you
lol, idk 'how' exactly, it'd depend on how the rest of your codebase is structured, but the underlying logic remains the same.
classes
member is guild, user is discord
id is still the same lmao
Ids dont change just cuz one is a member and one is a user object
well a user could also have a id per guild
no
i mean no
@modest maple does your netdata thing show your docker container names? or just the container id's?
i cannot get mine to show container names for the life of me lol
yeah that would be extremly stupid
@neat ingot container name
fml ๐
i was just wondering because why store member.id when you have member.user.id
did you have to do anything special to get it working?
nop
fmlllllzzzzz
just stuck it as a dameon and let it run lul
๐
there are settings that apparently change things
like, it tells netdata where your docker user group processes are running or some shit
@modest maple is there a reason for discord.js to store member.id when you have already member.user.id ?
and even though i 100% correctly gave the data and correct settings, it just does not show anything at all lol
i mean, obviously i didnt 100% do it correctly or it would have worked
but yea, as far as i could tell, i was doing everything correctly lol
@viral spade Cuz its discord.js lol, its awful
perhaps its just a convenience thing
My bot is randomly restarting sometimes, might this be because it's in the process of being verified?
no
Strange
probably your host if its not just a shard disconnecting
My bot is in 105 servers and I haven't implemented sharding yet
My host should, should, be fine
pretty sure discord severs connections after a few hours which would force a bot to reboot/reconnect
Weird
it could be a random bug in your code thats causing the bot to crash and reboot though
But it doesn't log anything
what host?
?
My host should, should, be fine
Who is your host
Vultr
lol, idk 'how' exactly, it'd depend on how the rest of your codebase is structured, but the underlying logic remains the same.
@neat ingot I did what I said, it did not work, so I'm not sure how I can do it, I tested it
dunno what to tell ya dude, you did it wrong ๐
I did this


