#development
1 messages · Page 15 of 1
honestly looks more clean as well
as well as it will combine your entire command object in one var
mostly named data I think
because scratch is keep going down.
what
ok use notepad?
are you looking for just a code editor?
nope
but?
he wanna learn how to make a bot from scratch
either limited to hours/months, blocked by discord (as we leanred today) or highly unreliable
things aren't for free that's how it is
Yep
so... nothing I can really recommend other than taking some money into your hands or asking some friend to be the host
you can try asking in #general but the result will be devastating probably
guys where do I code bot
hey how would i get the message behind a button interaction>?
as i want to delete it
wdym by behind it?
so like,:
if(interaction.isButton()){
interaction.message.delete()
}```?
each button is attached to a message right? I want to delete the message + button when clicking on it
The button interaction has a property called message which is the message the button been pressed on
This is just a djs message object you can use the common methods on
Like message.dekete()
you know fake, i would marry you.
it can't be ephemeral right
waghahahah thanks mate
No you can not delete ephemeral messages
lmfao
Finally I can
Just need to move to Brazil I guess
Tim, we’re divorced now
Send me 50% of your stuff

What a FakE bond!
🤦
Alright, I finished coding my custom commands system, but I have no idea how to activate it.
How will I be able to run this custom command made by the user on my message event?
module.exports = async (bot, message) => {
if (message.author.bot) return;
if (...) {
...
} else {
const server = await Server.findOne({ serverID: message.guild.id });
const prefix = (server && server.prefix) || process.env.PREFIX;
if (!message.content.startsWith(prefix)) return;
let args = message.content.slice(prefix.length).trim().split(/ +/g);
let cmd = args.shift().toLowerCase();
Commands.findOne({ //
serverID: message.guild.id, //
}, async (error, commands) => { //
if (commands) { //
let toExecute = commands.commands.find() //
}; //
}); //
let commandfile = bot.commands.get(cmd) || bot.commands.get(bot.aliases.get(cmd));
if (commandfile) await commandfile.run(bot, message, args).catch(error => console.log(error));
};
};
Alright, let's clear off things, I'm writing it where I put // up.
find the item where the property command equals the variable cmd you already have defined
then send a message containing the property value of the item you found
Alright, moment.
I believe like so:
Commands.findOne({
serverID: message.guild.id,
}, async (error, commands) => {
if (commands) {
const toExecute = commands.commands.find(x => x.command.toLowerCase() === cmd);
if (toExecute) message.channel.send({ content: toExecute.value });
};
});
Ayy, it works. Many thanks! :)

Would this be necessary, the !!! in: ```js
if (!!!commands.commands.find(command => command.command === commandToDelete))
Returning a boolean and checking if it's false.
Just use the some() method instead of find(), it returns a boolean
Fair enough.
even so !!! is the same as !
if statements already implicitly check things as booleans
why so many !'s
They wondered so much whether they could, that they forgot to wonder whether they should
fr
if you guys seperate ur functions into files by its relevance/importance/topic, what would be considered the main file then? do u have ur events in the main file or how does the main file look like
just trying to see how people handle their code
what i do I put everything in seperate files, the main file is the "loader" that loads all the commands and things
alright
you dont have to do it that way
I'd say its alot harder to manage big projects in the way i structure my projects
I thought of putting my events into main file and loading my bot from the main file, and inside the events I run my functions and inside the functions I await for other functions
and the functions I have separated into files so each task has their own function
just figure out how you feel the most comfortable in your project
I get aids when i see index.js files that are 1000+ lines
alright ic
yeah am trying to avoid that xd
one of my irl friends doesnt use exporting or seperate files at all
i was once over at his house and he showed me his bot
i was like "cool show me the source"
and he was showing me a file with 10k+ lines

that's a pain in the ass
it already gets confusing for me at 1K lines going up and down and trying not to get confused
https://www.virustotal.com/gui/file/94d589b77b71fec90a04cb54770f786999d7f78560c519fcaa0f3ea0cf20d7bd/relations
do u guys think this is safe?
VirusTotal
npm i discord.js@13
thanksss
xd np
if I import discord.js, what do I call this?
package?
basically I think I will make a file specially where I import all the stuff and then export it onto other files where I need them
so I assume I will name this file packages
import sharp from 'sharp'
import axios from 'axios';
import jsdom from 'jsdom';
import mongoose from 'mongoose'
import Canvas from '@napi-rs/canvas'
import booruData from './booruData.js'```
stuff like this in one file
Didn't know people use napi-rs/canvas
whats the point of importing everything in one file then export it into another? 👀
I mean… just 7 lines 
14 or so*
so basically I am using lots of functions
and events
I need to decide for where I save my functions ( separated in files inside folders ), my events and my imports
e.g. if all my functions in separate files are based on discord.js, would I have to import discord.js to every file that needs it
isnt that a good thing?
improved readability
what is?
I am just trying not to confuse myself with imports and exports
Well just create a class, put your methods inside and export it
Not only is importing in the files needed good for readability, which shouldn't be confusing you.
But also makes the compiler aware, especially in web site instances, what is needed by the file.
If you just import every single thing in your highest level you're going to end up with a very large bundle size.
having individual imports for what you need at the top of the file, not in another file then importing everything into every file.
You can take a quick glance at the imports and see whats needed.
More can be read on this by searching "Tree Shaking"
Construct the class in your index file and pass it in your command handler to your modules
Aka oop style 
I think I will just create a file that represents an import, e.g: all discord related functions go to the discord file ( which has the discord import ), all axios related functions to the axios file and so on
settings where I define the builder, client, intents, partials etc
functions for all the functions, including functions called in the event
weren't u the functional boy?
since when u converted to oop?
main file is just initialise the application with configs
but import hell tho 💀
me and the boys be using require()

more imports please ❤️
import * from <3
import * from <3
import * from <3
manually declaring require 
lazy requires ftw
🤔 I've never heard of that.
Why?
Just a faster startup?
how can i keep scrolling enabled but overflow hidden? it doesn't work..
i tryed elementname::-webkit-scrollbar display none and it doesn't work either
just set overflow: auto | scroll
you wanna hide the scrollbar or something
it is supposed to put this in a css file?
set the scrollbar width to 0
done
scrollable::-webkit-scrollbar {
width: 0;
}
done
yeah, i need the cold start to respond in less than 3 seconds
That's cool
it worked ty
i tryed that way but display none
and it didn't work
anyone have some regex to change xml into json 
too lazy to write it
it'll prolly be long asf
Someone told me that I can't parse XML with regexes, and I just had to prove them wrong.
bruh that's a short fucking regex
I imagined something wayyy longer
TypeError: string.replace is not a function
at toProperCase (/home/container/modules/functions.js:99:17)
at Object.exports.run (/home/container/commands/ipinfo.js:54:142)
?
the variable named string isn't actually a string
You can ensure something is a string by wrapping it in String(…)
hey guys, i want to host a little small site i made. However, if i actually host it on my vps i will need a domain name right?
not 100% required, you can use the ip in the url
Owhh awesome!
Thanks woo
what's a good hosting client that you guys would recommend? Apache?
but I'm not doing it the fuck
fetchIP.mobile ? "Mobile" : fetchIP.hosting ? "Server" : "Computer"
``` that's the line it happens at
I really like nginx
I used apache for years, used nginx once and never thought about leaving
do I need to somehow format this op?
could you post the section that uses .replace
since I dunno what you're trying to replace
though what @lament rock said, best is to wrap it
bro what the fuck
Missing } in template expression
my bad
how do I parse a domain into an IP again?
was it dns.promises.lookup or dns.lookup or what?
already got it working but ty
@bot.command()
async def help(ctx):
embed = discord.Embed(title = "Help", color = 0x00ff00)
# Loop through all the commands and add them to the embed
for command in bot.commands:
embed.add_field(name = f"{command.name}", value = f"{command.description}", inline = False)
await ctx.send(embed = embed)
@sharp saddle
ERR_TLS_CERT_ALTNAME_INVALID
never had this error before
but getting literally hundreds now
bruh, idk python
request to https://anti.fish/check failed, reason: Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:api-node2.phish.gg
N o t h i n g
there's probably an error but you aren't handling it properly
if it's a runtime error
(which it is)
make sure you aren't adding over 25 fields (i.e. commands) to the embed
25 is the limit
you don't have descriptions for some of your commands
I do
well from my code I do
print out the names and descriptions to your terminal just in case
order shouldn't matter
const mutedRole = await message.guild.roles.create({
name: "Muted",
color: "#000000",
reason: "Muted role for Butler Bot",
permissions: []
});
``` how do I make this role not allow people to talk?
that will allow them to talk, I'm looking to deny their permissions
Hmm
Let me check brb
Is this discord.js?
send_messages = false
@ancient nova
Let me know if that works.
I just realized I had to loop over all channels any deny their permissions like so
// Forgot about this, however we are going to need to loop over all channels to make the role "muted".
message.guild.channels.cache.forEach(channel => {
channel.updateOverwrite(mutedRole, { SEND_MESSAGES: false });
});
channel.updateOverwrite is not a function
what was it again if not that?
message.guild.channels.cache.forEach(channel => {
channel.createOverwrite(
mutedRole,
{ SEND_MESSAGES: false }
).catch(() => {
channel.updateOverwrite(
mutedRole,
{ SEND_MESSAGES: false }
)
});
});
``` maybe something like this? idk
didn't work
do I have to await that maybe?
wait don't tell me it changed names?
FetchError: request to https://domain.tld failed, reason: Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:api-node2.phish.gg
getting this for no reason 🗿
// Forgot about this, however we are going to need to loop over all channels to make the role "muted".
const channelsToOverwrite = message.guild.channels.cache.filter(ch => ch.deleted == false && ch.type === 'GUILD_TEXT');
for (const channel of channelsToOverwrite) channel.permissionOverwrites.set(mutedRole.id, { SEND_MESSAGES: false });
Cannot read properties of undefined (reading 'set')
why doesn't this work then?
this is so annoying what the fuck
const channelsToOverwrite = await message.guild.channels.cache.filter(ch => ch.deleted == false && ch.type === 'GUILD_TEXT');
for (const channel of channelsToOverwrite) {
channel.permissionOverwrites.set(mutedRole.id, {
SEND_MESSAGES: false
}).catch(() => {
channel.permissionOverwrites.edit(mutedRole.id, {
SEND_MESSAGES: false
}).catch();
});
};
``` ```Cannot read properties of undefined (reading 'set')```
WHY?????
Because permissionOverwrites doesn’t exist on whatever you’re trying to use it on? Bae you REALLY need to learn how to debug/read documentation
It would save you wonders of frustration and time spent waiting for a response
IT LIERALLY SAYS IT EXISTS ON THE DOCUMENTAIOTN KIFJIEJGIORGJOJGIOERJGOEJGEG
please end my suffering and tell me what's wrong
Again, debugging is yet another thing I suggested in that list
what am I even supposed to debug
It takes 5 seconds to log channel right before you try to set the overwrites
And also gives us more information
[
'734161576717844602',
<ref *1> TextChannel {
type: 'GUILD_TEXT',
guild: Guild {
id: '734161576285700186',
name: "Hater's Bot Testing Server",
icon: null,
features: [],
commands: [GuildApplicationCommandManager],
members: [GuildMemberManager],
channels: [GuildChannelManager],
bans: [GuildBanManager],
roles: [RoleManager],
presences: PresenceManager {},
voiceStates: [VoiceStateManager],
stageInstances: [StageInstanceManager],
invites: [GuildInviteManager],
scheduledEvents: [GuildScheduledEventManager],
available: true,
shardId: 0,
splash: null,
banner: null,
description: null,
verificationLevel: 'HIGH',
vanityURLCode: null,
nsfwLevel: 'DEFAULT',
premiumSubscriptionCount: 0,
discoverySplash: null,
memberCount: 5,
large: false,
premiumProgressBarEnabled: false,
applicationId: null,
afkTimeout: 300,
afkChannelId: null,
systemChannelId: '734161576717844602',
premiumTier: 'NONE',
explicitContentFilter: 'DISABLED',
mfaLevel: 'NONE',
joinedTimestamp: 1659225404765,
defaultMessageNotifications: 'ALL_MESSAGES',
systemChannelFlags: [SystemChannelFlags],
maximumMembers: 500000,
maximumPresences: null,
approximateMemberCount: null,
approximatePresenceCount: null,
vanityURLUses: null,
rulesChannelId: null,
publicUpdatesChannelId: null,
preferredLocale: 'en-US',
ownerId: '392035788004524043',
emojis: [GuildEmojiManager],
stickers: [GuildStickerManager]
},
guildId: '734161576285700186',
parentId: '734161576285700189',
permissionOverwrites: PermissionOverwriteManager { channel: [Circular *1] },
messages: MessageManager { channel: [Circular *1] },
threads: ThreadManager { channel: [Circular *1] },
nsfw: false,
id: '734161576717844602',
name: 'normal-cmd-testing',
rawPosition: 2,
topic: null,
lastMessageId: '1004177415901286422',
rateLimitPerUser: 0
}
]
it logs this
And this is channel, correct?
Because why is it an array?
That’s your issue right there for sure
Ah it’s because you’re looping over a collection with of
const channelsToOverwrite = await message.guild.channels.cache.filter(ch => ch.deleted == false && ch.type === 'GUILD_TEXT');
for (let i = 0; i > channelsToOverwrite.length; i++) {
channelsToOverwrite[i].permissionOverwrites.set(mutedRole.id, {
SEND_MESSAGES: false
}).catch(() => {
channelsToOverwrite[i].permissionOverwrites.edit(mutedRole.id, {
SEND_MESSAGES: false
}).catch();
});
};
Use for(const channel of channelsToOverwrite.values()) instead, otherwise you’re going to be getting [channelId, ChannelObject]
is this better?
breh
ok
@wheat mesa it worked
javascript is weird
It’s not weird
Djs/the base map class defined a [Symbol.iterator] for the class so that you can loop over it like that
And it happens to work like that
problem is that it didn't tell me that it was an iterator
I thought it would just return an array of channels
like it's.. kinda supposed to
A loop is quite literally an iterator
It iterates over each thing
Otherwise you would not be able to use a loop on the collection like that
it is? I could've sworn I used that kind of loop like what I sent above and it worked fine
However I’m not going to expect you to know that one since it’s a lesser known thing that you can do that with js
Forgot about it myself until now
Likely not, unless you used in and only needed the keys (I believe that’s how it works?)
btw my bot uses 400mb now 
I've honestly got no idea at this point, I only added afks to the cache and added 2 more things stored in the warn system that's all
but maybe the ram count wasn't accurate in the first place
I changed it from .totalHeap to .rss
Are you caching all your members, and is there any big libs that could contribute to that? Even djs shouldn’t be eating THAT much tbh
at first it jumped from 40mb to 200mb but now it's at 400mb almost
Does it grow over time
you think I have a memory leak?
Sounds like a memory leak to me
let me check what it is right now
last checked it was 400mb yesterday
huh it's exactly at 135.17 MB
maybe the memory leak happens when certain command executes or certain module is used?
Perhaps you just misread your ram usage
I can even go back and screenshot that for you
The largest item in memory is module strings
bruh 😭
imagine how much ram my bot gonna eat at 1k
Why I moved away from Discord.js
it sacrifices memory usage for type safety which I hate
Well tbh I’m using the default caching options and are by about 20MB usage for 400 servers yet
Dunno what people store or cache or how many junk vars they create
just to import Discord.js takes up 100MB on my end so idk what magic you're pulling
lol
dicksword.jayass
slash commands give you everything or almost everything
i dont need them?
they're still not going to make me want to switch to slash

i dont even check permissions

The message content intent enforcement might compel you to switch
Well 23MB now… what a peek
Errr no don’t think so
I don’t have to check permissions either. Only instance I should is if I join a vc, but I can just try to join it and if I don't receive a VOICE_SERVER_UPDATE in 5 seconds, it likely didn't happen
my heap was 40mb my rrs is 130mb now
You can barely even run a nodejs process on <30mb of ram (rss) tbh, much less maintain a whole bot + gateway connection
Checked, rss
Surely you’re doing the calculation wrong then… surely
Nope
Maybe he’s not even running v8, he’s running v25 
Lol
do you have an eval command?
You should try this to calculate https://github.com/AmandaDiscord/Amanda/blob/rewrite/source/utils/cluster.ts
process.memoryUsage().rss
K one sec
Lol
Those stats are always 1h old
do you host on windows?
your rss is swapped/paged out
thats why it shows 30mb
your heap is 250mb
Lemme check something
So what you’re saying is that if your rss is lower than your heap, then use heap for stats
you can do that

the os will always try to balance between physical ram and swap/page files
rss should represent whats on physical ram
heap should represent what the js engine is holding
there is no accurate way to calculate other proportions from inside the program i guess
there are tons of different ways of calculating memory usage
Ah interesting
windows has a "commit size" on the task manager
which is more accurate than the "memory usage" metric
because it also includes swapped/innactive
linux has a virtual memory, but its not really realistic in what it uses, it just says its allowed to use that much
I see you’ve been talking to speedy too much
or speedy's been talking too much to me
Lol
i always enable the "commit size" column on my task manager
Didn’t notice after moving it a windows vm
thats mozilla thunderbird btw
Probably was accurate in the Ubuntu built before
yeah it seems to be a very windows thing
it made me scratch my head when running memory benchmarks
for example i was making scripts to intentionally fill up memory
and i would see rss grow and then suddely drop to < 100mb
while the js memory kept rising
Hmm ok I see
Guess I’m gonna check for the higher value than on the next bot version
Or make it depend on the OS
speaking of rss, it feels like for me swap just doesn't get used at all lmao
is there some sort of common mistake i could be making
idk
are you hosting on windows or linux?
But interesting we figured that out, never really thought about the memory drop on the new VM
Not that it would be important in my case at all
But good to know
i think windows and linux report rss usage in different ways
its possible that both are using swap but linux includes it and windows for some reason doesnt
or they simply count it in different ways
i also cant find anything about it on google, the rss disparity between linux and windows in nodejs
Ok time to touch the default caching options then
Let’s agree on simply blaming @earnest phoenix for it?

lmao
linux
Just regarding the default caching options… does a member permission check require both roles and permissions to cache?
global permissions only need roles
channel-specific permissions need both roles and permissionOverwrites (and channels)
I need to check the dev docs again…
I think not only app permissions as field is available now, also member permissions is
I don’t remember anymore
Which shows the permissions of the app/member (if available) in reference to the current channel the interaction has been executed
Which completely makes role/permission caching obsolete tbh
Nvm
Just app permissions not member permissions
why am I being blamed?
And close above
going to sleep now, gonna watch your response later
Yeah, Windows reports RSS and similar memory usage diagnostics differently than Linux, which causes the values to differ, I'm not exactly sure in what way Windows calculates the memory usage but here's the source of process.memoryUsage() method if you want to look deeper yourself
JavaScript side implementation with binding call:
https://github.com/nodejs/node/blob/main/lib/internal/process/per_thread.js#L169-L178
C++ side implementation using memory tracker:
https://github.com/nodejs/node/blob/main/src/node_process_methods.cc#L179-L207
Memory tracker and retainers:
https://github.com/nodejs/node/blob/main/src/memory_tracker-inl.h
The heap statistics struct:
https://chromium.googlesource.com/v8/v8.git/+/refs/tags/10.6.85/include/cppgc/heap-statistics.h#19
The heap statistics getter:
https://chromium.googlesource.com/v8/v8.git/+/refs/tags/10.6.85/src/api/api.cc#8925
Ain't no way you looked this up
You…know he works on v8, right?
And since the RSS getters is defined in libuv, it's defined differently based on the operating system, and there are many different implementations, so I'll only list the popular ones here:
OpenBSD: https://github.com/libuv/libuv/blob/v1.x/src/unix/openbsd.c#L142-L160
NetBSD: https://github.com/libuv/libuv/blob/v1.x/src/unix/netbsd.c#L134-L161
FreeBSD / MacOS: https://github.com/libuv/libuv/blob/v1.x/src/unix/freebsd.c#L132-L157
Darwin: https://github.com/libuv/libuv/blob/v1.x/src/unix/darwin.c#L150-L168
Linux core (main Linux call definitions and core implementations): https://github.com/libuv/libuv/blob/v1.x/src/unix/linux-core.c#L158-L212
SunOS: https://github.com/libuv/libuv/blob/v1.x/src/unix/sunos.c#L617-L635
AIX: https://github.com/libuv/libuv/blob/v1.x/src/unix/aix.c#L993-L1014
And finally Windows: https://github.com/libuv/libuv/blob/v1.x/src/win/util.c#L525-L538
🤓
Congrats!
Yes I do
But I'd never actively look for that
i want that when a channel permission is updated then i can use the channel for my bot which event is this any one can tell me ?
const moduleLogger = await {
logSpam: function (_amount, _message, _settings) {
// CODE
}
}
``` is this not going to work when being called like so: `moduleLogger.logSpam()`
???
I have no idea what you're doing... ```js
const moduleLogger = await {
/*
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
*/
}
cause my VPS is going nuts
trying to make it easier to log, so I'm storing functions in a variable
That's not the point
Use classes for that
I have no idea what kind of syntax this is: const moduleLogger = await { }
Does it even let you do that?
Do you know what await does...
async would not make sense there either
how else would I use functions that need awaiting?
🤦♂️
Ever just have your piano start playing on its own?
you have ghosts in your house
You do know you should be awaiting it yourself
When you use it
And even then why are you awaiting something you're logging
I don't even know how to correct this syntax
You don't cause it's wrong to begin with :^)
yeah I fixed that
just use const moduleLogger = { ... } ig
What you're looking for is ```js
class ModuleLogger {
async someFunction() {
// ...
}
}
Guys, is there a way to create bot
Though const moduleLogger = { } stuff also works technically
That's creating an object manually
const moduleLogger = {
logSpam: async function (_amount, _message, _settings) {
}
}
If you intend to use this in multiple places, I'd suggest using a proper class
nope, only in a single script so no need to
People actually still use the function keyword?
it's quite complicated, I'd like to explain but I'll most likely do it badly and you won't understand anyway
I just use arrow functions
hey i was wondering how i made the webhook for top.gg to send to. I am using python. I am ok with using webhooks but i never tryed to set one up before?
I am trying to do it with out the of third party servacys and thats where i am stuck one
my method doesn't seem to work @wheat mesa
no errors though
should I just use a class? :/
You have provided no information on how your code looks, so I don't know
Usually there's no reason to manually construct an object like that
???
class ModuleLogger {
async logSpam() {
}
}
no function keyword is necessary
also, class names are PascalCase, not camelCase
makes sense
I got the API working but the docs dont say anything about time. instead of the last 1000 votes is it possible to see the ones in the last 30 minutes
should I do an auto role next?
I don't think I ever actually used classes in JS properly. I mean did before for a couple games I made but I forgot you didn't have to define a function that's why I got confused
How would i make it a requirement to upvote on topgg to use a certain command?
// If autorole is on, let's attempt at applying the role to the new member!
if (settings.autoRoleEnabled === "true") {
// Lets now attempt to fetch the role.
// We start by adding a couple variables we are going to use later.
const autoRole = settings.autoRole;
const mentionedRoleRegex = /^<@&(\d+)>$/;
// Now let's assign a couple variables that we are going to *edit* later.
let finalCheck, roleID;
// First lets start by testing by Id, mention and lastly by name.
if (mentionedRoleRegex.test(autoRole)) {
finalCheck = member.guild.roles.cache.get(autoRole.replace(/<@&(\d+)>/, "$1"));
} else if ((roleID = member.match(mentionedRoleRegex)) !== null) {
finalCheck = member.guild.roles.cache.get(roleID[1]);
} else {
finalCheck = member.guild.roles.cache.find(_role => _role.name.toLowerCase() === autoRole.toLowerCase());
}
const role = member.guild.roles.cache.get(finalCheck?.id || finalCheck);
if (role) {
// If role exists lets now add the role on our member.
member.roles.add(role).catch((err) => {});
// TODO: Logging confirmation.
}
}
anyone knows why this doesn't work?
can someone put it on a pastebin this is hell to read on mobile
I understand that pain
Discord needs to come up with a solution for codeblocks on mobile fr
Perhaps zoom-able UNWRAPPED text blocks
That will come in the update of 2060
If I had to guess I’d say autoRole.replace(longRegexImTooLazyToTypeHere, "$1") is wrong, since there should never be a $ in an ID when trying to get something from cache
: [
huh what do you mean?
This line
if (mentionedRoleRegex.test(autoRole)) {
finalCheck = member.guild.roles.cache.get(autoRole.replace(/<@&(\d+)>/, "$1"));
} else if ((roleID = member.match(mentionedRoleRegex)) !== null) {
finalCheck = member.guild.roles.cache.get(roleID[1]);
} else {
finalCheck = member.guild.roles.cache.find(_role => _role.name.toLowerCase() === autoRole.toLowerCase());
}
if (finalCheck) member.roles.add(finalCheck).catch((err) => {});
``` by the way I realized I fetched them 2 times
I thought this would surely fix it, yet it didn't
Not to mention I have no idea what that regex does
it replaces the "<@&" and the ">" parts from a mention to leave it be just an ID
Also why are you prefixing random variable names with _ now
that was old
But you’re replacing it with $1, no?
Log it, see what it is
$1 is supposed to return the value after regex has been parsed? am I stupid? lol
I don’t do regex stuff, but you’ve given it a string literal in the 2nd argument of a .replace call. Which from my knowledge is going to replace anything your regex matches with that string
Log it and check
If I’m wrong then I’m wrong, but it’s a possibility
👍
@wheat mesa it logged the ID of the role
Don’t know then, mobile formatting sucks so it’s not very easy to read
Plus it’s 2:30am so I can only do basic stuff in my brain rn
And I thought we are over this
const { Client, Collection, Intents, Modal, TextInputComponent, MessageActionRow, MessageEmbed, MessageButton, SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('account')
.setDescription('Command to generate an account'),
async execute(interaction) {
}
}```Why is it erroring: SlashCommandBuilder is undefined?
Because you didn’t import slashcommandbuilder from discord.js
At least… I can’t see it
Huh so far i haven't done that with any of my bots and they all work
how's that then>
Is exactly like you import client, nessageembed etc
I wonder do you need all this structures imported in that module?
Don’t see you using any of it at least no in that code snipped
No i do it on purpose so that i won't ever have an error whena dding something new to the code
You should only import what you need tbh
But anyways just add slashcommand builder to the import list
i see!
5|index | TypeError: SlashCommandBuilder is not a constructor
i think that my vps is running on the wrong djs version
TypeError: SlashCommandBuilder is not a constructor
bro what the fuck is this
update to v14
no i don't want to update to v14
yeah
Well it’s part of the builders package then, just with v14 they have moved into the djs package
I see
now it's throwing a tantrum of errors: 5|index | ReferenceError: SlashCommandBuilder is not defined
"discord.js": "^13.8.1",
In the first place update the package to 13.9
And yeah it’s not defined in discord.js but in the builder package
what's the builder package then
But don’t ask how to import it, never used builders 
“discord.js/builders” maybe?! Idk
Did you install the builders package?
import { SlashCommandBuilder } from '@discordjs/builders';
So the name should be @discordjs/builders
Yeah it worked now
fr some reason i had a mashup of v14, v12, v13 in my node_modules
i then forced uninstall, install and it worked
let detecrole1 = message.guild.roles.cache.find(r => r.name === "Wow Events");
let detecrole2 = message.guild.roles.cache.find(r => r.name === "FF Events");
let detecrole3 = message.guild.roles.cache.find(r => r.name === "Public Events");
let detecrole4 = message.guild.roles.cache.find(r => r.name === "Minecraft Events");
let detecrole5 = message.guild.roles.cache.find(r => r.name === "Other Game Events");
if(message.mentions.roles.first() !== undefined){
if(message.mentions.roles.first() === detecrole1 ||)
}```Is there any more efficient way of doing this instead of || marks (as i want to improve my habits lol)
I basically want to check if the pinged role is either role1, 2, 3, 4 or 5
[detecrole1, detecrole2, …].includes(message.mentions…)
Hi so um im actually using this to get a channel from its id.
return channel;```
But im not getting any data, this is a newly created channel
anything else i can try?
Owh whow i never thought of that, thank you man!
Try fetching the channel
how
channels.fetch?
i got an error for that
name:'DiscordAPIError'
method:'get'
message:'Unknown Channel'
httpStatus:404
code:10003```
getting this error
its a newly created channel, it says 404
am I using jsdocs right?
basically I wanna document everything I write in a file, from imports to methods to functions to returns
just use typescript ez
how did you create it?
Just the usual? Click on the plus button etc
Also all commands work there
not from code?
Nop
if you did not receive a channel_create event, then discord is broken
@quartz kindle btw Tim, just in case you didn't see my message
#development message
nice, thanks
i had a feeling it was os dependent
on windows v8 could try acessing commit size instead of active memory
usually commit size is much more accurate, from what i see in my task manager
Hmm weird but I can’t find it in the channel cache as well
do you have the guilds intent?
It basically says channel doesn’t exist
Yeah
It works if the channels already exist
try adding a client.on("channelCreate")
Mhm
How many times can you set slash commands in an hour?
Cause I'm no longer able to set slash commands in a guild since it's erroring.
const slashcommand = bot.slashcommands.get(interaction.commandName);
if (!slashcommand) return interaction.followUp({ content: 'An error has occured, whereas this command is no longer available.' }).catch(error => console.log(error));
Suddenly, returning the above error.
depends on your code editor, there are basically 3 types of jsdoc:
jsdoc
closure jsdoc
typescript jsdoc
I think I am using the standard one
depending on your programs, plugins, extensions, cli apps, etc
it might support a different one
vsc for example uses the typescript jsdoc
ohh
at least thats what i use
yeah I use that then
since i also have the typescript extension installed
and thats what intellisense shows me
typescript jsdoc doesnt support all jsdoc @ tags, only a few, but it does support all typescript typings
which makes it easier to use
the typescript website has a section for their jsdoc version
you can check that
Vsc jsdoc needs to be enabled right?
should be enabled by default
but strict typing is not enabled by default
so you wont get redline errors for types
the only relevant extension i have installed is intellicode
That's what I was thinking of, I'm going to enable that right now just to see how it works
you need to create a tsconfig file to configure it
the configs in vsc itself are not enough
vsc has these
which are enough to enable some type checking
but for full strict you have to do this
awesome thanks
do u guys know how i can be notified if ny bot goes offline?
Create a second bot that monitors the main bot
Or maybe set up a reminder on offline shards
well, today will be fun.
https://i.imgur.com/j5GYL5s.png
POV: you forgot a semicolon
thats what happens when you enable strict mode on js files :^)
how to get notified if the bot checking bot goes offline
You can get another bot and check if the status of said user changes to status type offline then send you a message.
i want something that alerts me, like an sms or sum
I have a question. 👋 https://cdn.hamoodihajjiri.com/5NoB2IdEzp
What can I do in order to continue with the let commandfile = ... code if the statement/condition of someStatement above is true (basically, get out of that code block): https://cdn.hamoodihajjiri.com/5NoB2IdEzp
Yeah but both bot should be running different places, for example if both running on same wifi and bot goes offline cause ur wifi is out, then you won't get notified
async (error, commands) => { ... } in other words async function(error, commands) { ... }
simply use return;
to end the function
Is there a way to find mutuals between one array and another?
Supposedly, I have an array called ignoredRoles which are full of role IDs, and in my message event, I want to see that if the user has any of the ignoredRoles, then return.
How can I achieve such so.
roles.some(r => ignoredRoles.includes(r))
Fair, how about if I have multiple checks, what can I do?
!toExecute
!toExecute.ignored.channels.includes(message.channel.id)
!message.member.roles.cache.some(role => toExecute.ignored.roles.includes(role))
Those are my three checks. Apparently, if I return; for one check, it's going to just not look at the rest of the code within the function, so?
I made one huge if statement like:
if (toExecute && !toExecute.ignored.channels.includes(message.channel.id) && !message.member.roles.cache.some(role => toExecute.ignored.roles.includes(role.id))) message.channel.send(...);
there are many ways of checking for uptime, for example run a webserver inside your bot that accepts ping requests, there are many free services that ping your webserver every 1-5 minutes and send you an email/sms if the ping fails
another way is to use a process manager to manage your bot process, many of them can be configured to notify you via email if the process restarts
that is smart idea, never thought of that way
Love this bot
Hello, how do I use discord.js collector on discord buttons?
made a library to create these, have fun https://github.com/lutzseverino/discord-books
I want to make it so pages don't have to be static so any feedback on that (or anything else regarding the library) is appreciated, :)
You’re library is using Java. They are asking for Discord.js. Don’t just reference your stuff if not needed 💀
I don't think what he's saying has anything to do with the question. He's just asking for feedback
Which is perfectly fine
I wasn't responding to the other guy, i was just asking for feedback :)
yeah what the waffle said
minimodding fail
ohno, a new competitor 
lol i use so sure no one else had made something like that
ah yours uses reactions so together we cover every edge case
hmm yes i see. I'm reading the readme right now
reactions were kept for compatibility with older models (or use buttons in user messages)
didn't update the gifs yet, it's a pending project
I'm just waiting for jda to release a stable version so I can build on top of it
what are the chances though holy shit
lol
i made a library to create book messages ^
Oh pagination?
and this other guy also made a library that is similar
jda's "official" paginator is...let's say "peculiar"
Until his library made me get 429nd out my ass
I swear I NEVER managed to make jda-utilities work
yeah basically, though mine only works with buttons, honestly i didn't even think about reactions
i won't be covering it though tbh unless someone PRs
fixed in nightly version
lmao
my library is cooler though guys believe me
I was shocked when I realized you were that guy
Before I never interacted with you on topgg and then I realized you were that guy and was like damn
top 10 anime plot twists
Is it in kotlin?
Tf
it's full circle
I think the last time I used java was to make a parser
kotlin wasn't really a thing when i started and i never made myself learn it
Back in 1912
yeah but it took off fairly recently. google saying it was the preferred language for android etc
I mean kotlin is nice ngl
I love java but fuck android api
I'd prefer it over normal java
why did they have to rewrite the ENTIRE java ecosystem?
no, I mean android itself
all my homies use BufferedImage but no, let's use Bitmap tf
wanna use Color? too bad, figure out how to use this 100% incompatible class
Makes sense
anyways if someone knows Discord4J and wants to provide (or help) the impl for the library i posted it would be great
made it for JDA only now cause i have literally never touched Discord4J. It's pretty different as far as i can tell
Discord4J is still around?
I didn't think anyone really used it
client.guilds.leave('guild id')
kk
Time to get your IP
cache guilds and find unusual names, ez.
lmao
my ip is 127.0.0.1
Hacked
guess what!
Get trolled
HH
what a coincidence!
Also I just remembered that this is no longer an allowed topic
Dylan warned me a few days ago about it

yeah? mine is fe80::7709:b321:f506:6560. I'm living in the future
dayum
me when ip 7F000001
nice
but really, I fear a future where u wont be able to memo your own ip
Did you just throw out a hex code
ipv6 is just hardcore
What color is that
mine is 3j.0.0.1
that's localhost without .
oh wait, what is the color of localhost
Yea
unless we achieve LEV we'll be dead by then
ooh
Everything has a color
hey guys im mapping a list of admins, but I need a variable name. do I call it;
admins, adminList or adminMap or... administratorList or..
So localhost is just black?
your pages are also made of static content right? @lyric mountain
It will be an array so just go with admins
indeed thats a cool way to represent it xD
Imagine it all IPs had a color
am I doing good spacing here?
slightly blue and 50% transparent
intellij shows in RGBA format, but the universal standard is ARGB
arrhhhgb
depends on your style
I would tab twice on method chains
^
^
ayo?
ah the forms dude
hi lol
hi
also return the value directly instead of assigning to a variable and returning it
node probably does that internally tho
bruh
just return the string literal
💀
i'm still thinking of a way to properly store configs in browser's storage
what framework is that?
custom-defined file
i used jotai for storing states
it's a react web app
it's kinda stored like
key | value
System.Time.UseMiliatary true
System.Time.GMTOffset 7
Clock.BlinkAnimation true
Clock.DefadeZerosOnHover true
maybe i can do like
key: Config
value: "{
"System": {
"Time": {
"UseMilitary": true,
"GMTOffset": 7
}
},
"Clock": {
"BlinkAnimation": true,
"DefadeZerosOnHover": true
}
}"
but modification requires writing stuffs on the browser often
System:
- Time:
- UseMilitary: true
- GMTOffset: 7
Clock:
- BlinkAnimation: true
- DefadeZerosOnHover: true
can i use yaml in browsers?
hm, idk how fast json -> object conversion is, but maybe u could use some easily parseable format
like properties
System.Time.UseMiliatary=true
System.Time.GMTOffset=7
Clock.BlinkAnimation=true
Clock.DefadeZerosOnHover=true
how often? ive seen people do cookie clicker and write to localStorage without any major drawbacks
just iterate over the lines and split by =
shit's 3874 lines
yaml-parser
you could try to benchmark it to see what's faster for u
prolly alot later with introduction of background processes
properties is fast af cuz u don't need to parse the whole thing at once
line-by-line parsing right
my i18n file uses it, and has 630+ lines
ye, check the key before trying to parse
if it doesn't match what ur looking for just step over
oh also
there's a format I use for my dictionary files
shit's like ```js
config.map(({key, value}) => ${key}=${value}).join('\n')
but then i still have to do iteration
I pre-map the lines where each letters starts
so when reading, I can simply jump to it and start checking from there
first line is max size of line number
second line are the letters + line (like a000002 means letter a starts at line 2)
and this file is...big
perhaps i can do that
u could do something similar but using the keys instead
like, System starts at line XXX, Clock at YYY, and so on
although you'd need to figure a format that allows multichar indexing
just go by initials then
like what I did, you'd just need to update the index if u change the structure
nono, just s
i just gotta make sure that the keys are not overlapping
unless u have a huge amount of settings under system
you bet
since it's an os
💀
hm
yeah so i wanna make it as performant as possible
ok so, you could index by 2 letters then
sy
or whatever, 3 letters as u said
stg
this is what I use for reading and going to the line
for example, b indexation would be chars 8 to 12 (AxxxxxxB|xxxxxx|)
then I return false if I reach a line where the letter is different than the current (since I cant have a word that begins with b inside c section)
or true if I do find the word
only for the line numbers
so u can get a substring of it relying only on char index
ohhhh
a000002b028596c041399d072604e084433
means
A -> line 2
B -> line 28596
C -> line 41399
D -> line 72604
E -> line 84433
and it can be easily generated by code
yes
if you want as performant as possible, json will likely be faster, unless you know what you're doing
you're reading/writing the entire thing to/from localstorage?
like serializing every time?
keeping it in memory would be pretty bad no?
never know when the tab closes unexpectedly
so i call for each write just in case
export const findFriendlyChannel = (guild) => {
let found
guild.channels.cache.map(async (channel) => {
if (!found && channel.type === "GUILD_TEXT") {
if (channel.permissionsFor(client.user).has("VIEW_CHANNEL") && channel.permissionsFor(client.user).has("SEND_MESSAGES")) {
found = true
console.log(channel)
return channel
}
}
});
}
const friendlyChannel = findFriendlyChannel(guild)
console.log(friendlyChannel)
why is friendlyChannel returning undefined even though I am returning channel which is the channel object
async cant interfere on sync scope
bro what is this
?
i can't read
yeah I made the map sync now
[ original msg deleted ]
then none fulfills that condition
the only logic that makes sense in js
then u go to php and explode()
export const findFriendlyChannel = (guild) => {
for (const channel of guild.channels.cache)
{
const hasPermission = (permission) => channel.permissionsFor(client.user).has(permission);
if (channel.type === "GUILD_TEXT")
if (hasPermission("VIEW_CHANNEL") && hasPermission("SEND_MESSAGES"))
return channel;
});
}
@earnest phoenix
my take on it
can be a one liner 🙃
so do I use find, for loop or my mapping

i'm using for(const element of array) for perfomance
true but not noticable unless the guild has a hundreds of thousands of channels
but for readable you can use array.find
ic
map is like const mapped = <array>.map(elem => "amogus")
also
pointless var assignment
you return on first channel found
no need for looping entire thing
for transforming values of an array to a new one
I paid for O(n) I'm gonna use the entire O(n) 
ok im using .find
for iteration, array.forEach exists

reduce returns a minecraft piston 👍
oo, good to know
ah, shape assignment
what is i?
yk, that's why rubberducking works
In software engineering, rubber duck debugging (or rubberducking) is a method of debugging code by articulating a problem in spoken or written natural language. The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, l...
Yeah but the problem is with message.createMessageComponentCollector()
what abt it?
I mean, is ur filter right? try adding a console.log inside it to see if it is collecting
message is not defined
Its a reply
where do u declare it?
ur not declaring it
that'd be const message = await interaction.reply(...)
if it does return a message
quack


