#development
1 messages · Page 2072 of 1
Am I the only one who starts shard ids at 0?
No, we're all like so.
But question...
What can I do, instead?
if you have 2 shards, it should log twicr
The whole bot started running twice.
API events ran twice, etc.
Which, particularly?
like shards: "auto"
Oh, yes I am.
However, right now it's on 2, reason is is because whenever my real bot is on two shards, it crashes and never runs.
So I'm trying to test out why so on my testing one.
Hi, i got this error, i googled it, nothing, can someone help?
if (interaction.customId === 'prev') {
searchResult.prevSearch();
} else if (interaction.customId === 'next') {
searchResult.nextSearch();
} else if (interaction.customId === 'cop') {
await interaction.reply({ content: 'You copped this image.', ephemeral: true });
} else if (interaction.customId === 'drop') {
await interaction.reply({ content: 'You dropped this image.', ephemeral: true });
}
When i press cop or drop it's showing this in console:
Error [INTERACTION_ALREADY_REPLIED]: The reply to this interaction has already been sent or deferred.
at ButtonInteraction.update (C:\Users\renat\Desktop\cop or drop\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:210:46)
at Client.<anonymous> (C:\Users\renat\Desktop\cop or drop\index.js:65:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
[Symbol(code)]: 'INTERACTION_ALREADY_REPLIED'
}
C:\Users\renat\Desktop\cop or drop\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:94
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
^
Error [INTERACTION_ALREADY_REPLIED]: The reply to this interaction has already been sent or deferred.
at ButtonInteraction.reply (C:\Users\renat\Desktop\cop or drop\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:94:46)
at Client.<anonymous> (C:\Users\renat\Desktop\cop or drop\index.js:71:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
[Symbol(code)]: 'INTERACTION_ALREADY_REPLIED'
}
PS C:\Users\renat\Desktop\cop or drop>
it s showing this
and crashes
same for drop
show the rest of the code
Did you defer the response before replying?
If so you can’t reply anymore but edit your reply (which is the deferring itself)
client.on('interactionCreate', async interaction => {
try {
if (interaction.isCommand()) {
const command = client.commands.get(interaction.commandName);
if (!command) return;
await command.execute(interaction);
};
if (interaction.isButton()) {
const message = interaction.message;
const messageID = message.id;
const searchResult = await resultMap.get(messageID);
if (interaction.customId === 'prev') {
searchResult.prevSearch();
} else if (interaction.customId === 'next') {
searchResult.nextSearch();
} else if (interaction.customId === 'cop') {
message.reply({ content: 'You copped this image.', ephemeral: true });
} else if (interaction.customId === 'drop') {
searchResult.nextSearch();
}
const oldEmbed = message.embeds[0];
const newEmbed = new MessageEmbed(oldEmbed)
.setDescription(`Result ${searchResult.currentResult + 1} of ${searchResult.resultArray.length}`)
.spliceFields(0, 1, { name: searchResult.currentSearch().title, value: searchResult.currentSearch().displayLink })
.setImage(await searchResult.currentSearch().link);
const actionRow = message.components[0];
actionRow.spliceComponents(4, 1, new MessageButton()
.setLabel('View Original')
.setStyle('LINK')
.setURL(searchResult.currentSearch().image.contextLink)
);
await interaction.update({ embeds: [newEmbed], components: [actionRow] });
return;
}
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
tried to edit, nothing.
Huh
if u going to take a long time (longer than 3s) to update an interaction u need to defer
and this
is going to clash with this
ah nvm, it'll enter in one of the two
I just want it to reply to the message
try deferring
and remember, u can't use reply, update, deferReply or deferUpdate twice for the same interaction
Tried
13
the latest version has no update() method for a command interaction
oops
it's a button interaction
I see
Yes, it s button
anyways, after this is fired
message.reply({ content: 'You copped this image.', ephemeral: true });
you can't respond with this
await interaction.update({ embeds: [newEmbed], components: [actionRow] });
since you already responded
whatever 'You copped this image.' means requires you to return this reply
to stop the coding from going on
or if both messages are needed, you have to send a followUp response
But message.reply isn't ephemeral
It can't be ephemeral
You're responding to a message not an interaction
const message = interaction.message;
Responding to the interaction is interaction.reply(...)
Calling reply() on the message object will simply send a normal message to the channel (requiring a gateway connection) and has nothing to do with an actual interaction response which is a webhook
You can only respond with an ephemeral message to an interaction
But you choosed to respond to the actual message not the interaction
like when you click on drop to show that
Did you read what I wrote above?
Stop replying to the message
Reply to the actual interaction
message.reply({ content: 'You copped this image.', ephemeral: true });
interaction.reply({ content: 'You copped this image.', ephemeral: true });
And keep in mind you can't responde a second time await interaction.update({ embeds: [newEmbed], components: [actionRow] });
This does not work
is from interaction.reply
You need to do a follow up message
For your second response just check if the interaction was already responded to
if(interaction.replied) await interaction.update({ embeds: [newEmbed], components: [actionRow] }); else await interaction.followUp({ embeds: [newEmbed], components: [actionRow] });
sorry for late reply, but cant do that cuz this isnt a command, its an interval which checks new activity of user on a platform. if it gets new activity it sends a private message to the user
...it doesn't need to be a command
wherever u can use .cache us can use .fetch
yeah ik and i cant fetch every 5s....
not risking being rate limited
what part of "it won't call the api every time" didn't u understand?
fetch will only call the api IF it isn't cached
mmmm okay cool then
also depending on what ur doing sending a message every 5s is the actual danger
not the fetch part
Hey, for my case, what can I be doing instead to safely spawn all shards? 
thats what i am doing^ well if you know what nfts are i can explain more
well, no problem then ig
Fair, however, manager.shards.size === manager.totalShards returns false, so it's not broadcasting the code I want to broadcast?
require('dotenv').config();
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./src/index.js', { token: process.env.TOKEN, totalShards: 2 });
manager.on('shardCreate', shard => {
shard.on('ready', () => {
if (manager.shards.every(x => x.ready) && manager.shards.size === manager.totalShards) manager.broadcast('allReady');
console.log(manager.shards.every(x => x.ready));
console.log(manager.shards.size === manager.totalShards);
});
console.log(`[SHARDS]: Launched shard ${shard.id}`);
});
manager.spawn({ delay: 10000, timeout: -1 });
forget checking shards size damn
Alright, I will.
just make a promise that awaits until all shards have started status
But for first?
Like so, correct? https://cdn.hamoodihajjiri.com/Xdq9tzXbvV
do that outside of any shard event
right after you create the manager
do not proceed until everything is started
What do you mean? I'm confused on that part.
What should the promise contain, and where should I be resolving?
Which events?
I have them in a folder, but I'm confused on what you mean.
where is the place where you attach the events to the manager?
eg. shardCreate is an event
messageCreate is too
Yes, however, all related shard things is in one file which is shard.js?
You don't need to attach the events to the manager other than shardCreate
Because those other events are attached to the shardClients themselves
At least that's how it works in detritus
I mean, he wants to await all shards to be ready before continuing, so you'd have to do that after you create the manager and before you allow interacting with the bot
idk where that'd be in d.js
Honestly, yes. This is the issue I'm facing, trying to get all shards to be ready before I can continue, but honestly, I'm having difficulty on what I'm doing.
There is two solutions:
A.
here's how I do it (JDA), just to show what I'm trying to say
in my case I do it async because I don't need for all shards to be ready
if I had to I'd just remove the executor
I can either use manager.broadcast and add a process.on('message', async message => {}; to get the code and continue with the ready event, or just wait for all shards to spawn (which I'm not sure how).
this would halt the initialization until every shard reported status READY
<ShardManager>.spawn is a promise
Yes, I'm aware.
I was going to say await it but I suppose that doesn't solve anything really
Yeah, shards would still be spawning.
My only issue is to how to await all shards to be ready before continuing.
why do you want that in the first place
I have two shards.
and?
In the ready event, I have broadcastEval.
I can't execute it without having all shards ready.
what does the broadcastEval do
Logs server count, member count, and channel count.
why not do that from the manager
Cause the shards are not ready.
await the spawn call
That did nothing.
it should resolve after all the shards are spawned
I mean, I should be adding a self-calling function, correct?
No I mean... log the server / member / channel count in your sharding manager code, not in each individual shard or the first shard
However, I'm using broadcastEval?
...so what
How am I supposed to achieve so?
(async () => {
const shards = await manager.spawn({delay: 10000, timeout: -1});
let guildCount = 0;
for (const [, shard] of shards) {
guildCount += shard.getClientValue("guilds.cache.size");
// other...
}
console.log(`Guilds: ${guildCount}`);
})();
try this
Yes, however, I'm using bot as in Discord.Client()?
I cannot use it while I'm spawning shards first.
I'm aware, you know how shard.js is executed then index.js?
let activities = [`${(await bot.shard.fetchClientValues('guilds.cache.size').then(total => total.reduce((a, b) => a + b, 0))).toLocaleString()} servers!`, `${(await bot.shard.fetchClientValues('users.cache.size').then(total => total.reduce((a, b) => a + b, 0))).toLocaleString()} members!`, `wefwefwef`], i = 0;
setInterval(() => bot.user.setActivity(`${activities[i++ % activities.length]} || /help`, { type: 'PLAYING' }), 60000);
I have something like thise code.
I cannot put it in the shard.js file since I have bot.user?
I don't understand what you're asking just try the code I sent you
that shouldn't matter
Another question for the day😹
My system is a little complex so i am running into some problems tdy
Any idea how i can check if a user has a specific role in a specific server
Not by using message.guild.roles.find(role => role.id === "id"); //Find member
As i have to search for the role & user without a command
@cinder patio, here's a solution that I may want help in, I add in my ready.js file // process.on('message', async message => {}; and checking if message is equal to the code of something like manager.broadcast('allshardsready'), if you got what I mean.
Would that be possible?
If it is, then it would execute the code in the ready.js file, otherwise, wait for the shards to be fully ready.
Any idea?
fetch the guild and the user in the guild, compare roles
(async () => {
const shards = await manager.spawn({delay: 10000, timeout: -1});
for (const [, shard] of shards) {
shard.send("allshardsready");
}
})();
could work
I don't know if spawns just waits for the processes to spawn or if it waits for each shard to become ready
try it
However, is this code correct? https://cdn.hamoodihajjiri.com/7c4AXvTDEu
Not sure how I'm supposed to check with message.
use bot.shard.on("message"
<GuildMember>.roles.cache.has('ROLE_ID');
Where should I be using this?
How to change the color of the button?
Tell me that few styles
try
const { parentPort } = require("worker_threads");
parentPort.on("message" ...
Well, this works, too: https://cdn.hamoodihajjiri.com/CTSNQNmUaE
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
if it works then why are you asking me if it's correct
No, I just realised it now, that's why.
The only issue I'm facing right now is getting all shards ready, and I'm currently trying your code.
However, why did we skip collection 0?
huh? is it working
It's running, moment.
we're not skipping anything
[, shard], what does this mean?
(async () => {
require('dotenv').config();
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./src/index.js', { token: process.env.TOKEN, totalShards: 2 });
manager.on('shardCreate', shard => {
console.log(`[SHARDS]: Launched shard ${shard.id}`);
});
const shards = await manager.spawn({ delay: 10000, timeout: -1 });
for (const [, shard] of shards) {
shard.send('allReady')
}
})();
Fair enough, here's what I did, but ready.js isn't firing.
Is it because of shard.send()? Do I put manager.broadcast('allReady'); instead.
no, process.on probably doesn't work
or
add this in the loop
console.log(shard.ready);
and tell me what it says
"GuildMember" as his id?
true, false.
You need the GuildMember object, it could be like message.member.
Yeah ik but how can i get it with just the id of the user and id of guild?
Yeah i did that
(await <Client>.guilds.cache.get("GUILD_ID").members.fetch("")).roles.cache.has("ID");
and then that ^
Okay let me try
@winged linden
Okay
okay then do this
let ready = 0;
manager.on('shardCreate', shard => {
if (shard.ready) ready += 1;
else {
shard.on("ready", () => {
ready += 1;
if (ready === manager.totalShards) {
for (const [, shard] of manager.shards) shard.send("allReady");
}
});
}
});
Done, how about the code in the ready.js, does it stay as it is?
Or do you want me to modify something? https://cdn.hamoodihajjiri.com/LhAfrKVP7T
Alright, I'm launching the bot.
Then the guild isn't cached. Fetch it first
(async () => {
require('dotenv').config();
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./src/index.js', { token: process.env.TOKEN, totalShards: 2 });
let ready = 0;
manager.on('shardCreate', shard => {
if (shard.ready) ready += 1;
else {
shard.on('ready', () => {
ready += 1;
if (ready === manager.totalShards) {
for (const [, shard] of manager.shards) shard.send("allReady");
console.log(ready);
};
});
};
console.log(`[SHARDS]: Launched shard ${shard.id}`);
});
await manager.spawn({ delay: 10000, timeout: -1 });
})();
This is what I exactly did, and still, nothing logs.
Do this instead of process.on
TypeError: Cannot read properties of null (reading 'on')
Didn't I do that?
Ah, wait.
only 1?
Same code but:
shard.on('ready', () => {
ready += 1;
if (ready === manager.totalShards) {
for (const [, shard] of manager.shards) shard.send("allReady");
};
console.log(ready);
});
Yup, for some weird reason.
but did you wait 10 seconds
Updated code: https://cdn.hamoodihajjiri.com/fkqiwQu3Rx .
Yes, I did.
Also, look at this:
[SHARDS]: Launched shard 0
1
[SHARDS]: Launched shard 1
It logs before shard 1 spawns.
did you wait
Yup, reaching a minute now.
so shard 1 is not emitting ready for whatever reason
Yes.
@cinder patio , it worked.
[SHARDS]: Launched shard 0
1
[SHARDS]: Launched shard 1
2
Shard ID 1 [...]
Shard ID 0 [...]
so you had to wait
Nope, I restarted and it works.
However, I'm so confused why my early code didn't work?
I was checking for the exact same thing?
Yes.
Alright, so this is the code you showed: https://cdn.hamoodihajjiri.com/QRC3VoBac3 .
I don't even remember the old one, but let me re-create it.
didn't you send it in here already
(async () => {
require('dotenv').config();
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./src/index.js', { token: process.env.TOKEN, totalShards: 2 });
manager.on('shardCreate', shard => {
shard.on('ready', () => {
if (manager.shards.size === manager.totalShards && manager.shards.every(x => x.ready)) for (const [, shard] of manager.shards) shard.send('allReady');
});
console.log(`[SHARDS]: Launched shard ${shard.id}`);
});
await manager.spawn({ delay: 10000, timeout: -1 });
})();
Here, I rewrote the code.
This is what you told me and this is also my code, I merged it.
And it works. 👍
Alright, code works extremely well, just last thing. I have my ready.js file, and you know, depending on how many shards are spawned, it will equal to how many times the code will be executed inside the ready.js event. Is there a way I could check the amount of shards being spawned?
As in { token: process.env.TOKEN, totalShards: 2 });.
bot.shard.count?
It will straight equal to totalShards:, right?
yeah
Aha.
Indeed, I'm at 9 servers, right now.
Jk, 1.1k and the bot is barely handling.
Indeed, however, what I did now is a fix, I fixed not being able to spawn multiple shards, that's all.
Slash commands aren’t different to common commands except that you have to specify a name and description for it.
Once you wanna setup command options things are actually quite different as those options need to be registered and you have to choose from a list of available option types
But your in code argument parsing and handling isn’t really something you can transform to slash command options automatically
The earlier getting into it the better
Who knows if the message content intent really comes this fall or will be delayed once again
So be prepared
I think they're sticking to the deadline at this point unless something goes wrong for some reason
I think the April 2022 thing was to make people think they HAD to switch over by then, but then they extended it for the few who were too lazy to do it in that timeframe
So that people don't get screwed and they also have more time to review message intent applications
hey guys how do i re-register all slash cmds?
Because i changed some file names, thus some commands in the handler
now it;s throwing: DiscordAPIError[50035]: Invalid Form Body
0.options[0].name[STRING_TYPE_REGEX]: String value did not match validation regex.
It means that some of your names are invalid
You should probably not have your command names rely on the file name
Do any of your slash commands have names with any capital letters in them?
I see, i've fixed it!
They had a space in them.
the transition to v13 is really hard, but this server seems to be helping me a lot. Really grateful!
Good to hear you're porting to v13
And v14 is coming out soon
Is it possible to remove a fulfilled promise from an array to run promise.any again to find the 2nd fastest array? Im using .filter but cant get it to work
Has been a good joke for 6 months or longer
you need to figure out the index of the promise and remove it
I cant, when i log something like promise.config, it returns promise instead of promise.config
you need to add a way to identify them
for example ```js
const index = array.length;
const promise = something().then(result => ({ result, index }))
array.push(promise);
then you can do ```js
const { result, index } = await Promise.any(array);
array.splice(index, 1);
About 10k+ , so there are 10 shards
I’m still facing the issue btw
Apparently it’s not working in some servers but works in others
Is there anything I can do to figure out what the issue is
I don’t see any crash errors in my error logs
Very weird
Anyone knows how to add support for syntax highlighting in floating windows like fzf in vim/neovim?
Not really development but still
You can just get the index like that???
Oh I understand noww
No one can help if they don't know your issue
okay, i've called 911 to come to your house
Well the bot randomly stops working in some servers
And works on others
I’ve checked for crash logs or any other errors but nothing shows up
It doesn’t make sense tbh
So promise.any returns the promise that is fulfilled in all levels. Not just only on the first level?
I’ve called 911 since you’ve called them for no reason
no i've called 911
does anybody know how to setup a vps for replit and glitch ( like videos ? )
Why this? I just realised.
If I have two shards and I log bot.shard.broadcastEval(client => console.log(client.shard.ids)), it does [ 0 ] then [ 0 ] [ 1 ]
lmfaooo imagine spending 10 hours to port to v13 and v14 comes and changes EVERYTHING again 
is there a workaround to log if a bot delete a message?
since it didn't appear in the audit log, how can i get the bot that delete the message
yes but how can i get the bot that deleted the message
when you grab the message callback just do message.author
that would be the author of the message
what i'm trying to get is who delete the mesage
ohhh
Nevermind, I figured it out.
Do note these are impossible at the time of writing this and will return 'Unknown':
• See which bot deleted a message as Discord does not log message deletions for bots
• See if the author deleted their own message (Discord does not log this either)
• 100% determine if the message deleted matches the fetched audit log due to Discord not including the message ID in audit logs
oof i see this
oh well then I guess it's impossible
I have this broadcastEval() code, however:
bot.shard.broadcastEval(client => console.log('Shard ID', client.shard.ids[0], client.guilds.cache.map(guild => guild.name)));
When it comes to the results of the guild names, I can see, supposedly, guild called ABC in shard 0 and shard 1? What does this mean and is there something I should be doing?
Log the debug event and see if something's amiss
What?
is anyone here good at moddeling? 😭
Not talking to you, talking to @crystal wigeon
Modeling what—bananas?
I have a 🍌 you could use as a model
I mean it happens after like 5 - 6 hours
I’ve got error logs on crash and process exist
Yeah, do that
Exit
yes
Create attachment
but
Mmm gotcha thanks
because each shard will report what they see
like, imagine we have a ballot box and 5 people, each will add a ticket to it
first person will see the box empty and say "there are 0 tickets"
the second will see a single ticket and say "there's 1 ticket"
the third "there're 2 tickets"
and so on
async operations dont know other async operations exist, unless you make them
Ahh, fair enough.
Facing this issue, currently, however.
show your client options
where you do new Client(...)
const bot = new Client({ allowedMentions: { parse: ['everyone', 'roles', 'users'], }, partials: ['MESSAGE', 'CHANNEL', 'GUILD_MEMBER', 'GUILD_SCHEDULED_EVENT', 'REACTION', 'USER'], intents });```
show your sharding manager file again
from inside the client file, console.log(process.env.SHARDS, process.env.SHARD_COUNT)
await Promise.any()
How do I return null if this code returns [AggregateError: All promises were rejected]
try{}catch{} doesn't seem to work
.catch() seem to work but, how can I return null?
now console.log(client.shard.ids)
both should work
console.log(process.env.SHARDS, process.env.SHARD_COUNT);
console.log(bot.shard.ids);
[SHARDS]: Launched shard 0
0 2
[ 0 ]
[SHARDS]: Launched shard 1
1 2
[ 1 ]
everything looks fine
just tested it, it somehow worked for actually no reason...
Alright, lemme reproduce the issue, moment.
i dont see how this ^ would be possible
Alright, look at this:
bot.shard.broadcastEval(client => console.log('Shard ID', client.shard.ids[0], client.guilds.cache.map(guild => guild.name)));
``` ```js
Shard ID 4 [ "Alright, Don't Ask" ]
Shard ID 5 [ "Alright, Don't Ask" ]
Shard ID 3 [ "Alright, Don't Ask" ]
The same server in 3 shards?
well you're not supposed to shard with 9 guilds only, that's what's probably going on
console.log the same stuff as before
Alright, moment.
[SHARDS]: Launched shard 0
0 8
[ 0 ]
[SHARDS]: Launched shard 1
1 8
[ 1 ]
[SHARDS]: Launched shard 2
2 8
[ 2 ]
... and so on
log the guild ids
Yup, it logs the same IDs.
youre sure youre not fetching that guild somewhere?
Let me comment out this: https://cdn.hamoodihajjiri.com/oJroyjj2Zv .
I was.
that should be it then
Yup, it now works. However, how will I be able to get the guild ID and post the commands?
Do I use bot.guilds.cache.get instead or?
Since I'm using (await bot.guilds.fetch('737011108954505267')).commands.set(commandsArray.flat());.
commands are a one time thing, it should not be set on every run
I realised.
put the command setting in a separate script, and run it only when you change something
you also dont need to login to do that
Also, when every shard gets ready, my slash command handler file runs.
thats fine
Even events.
Fair, but how about those?
https://cdn.hamoodihajjiri.com/or4Yu5Vlfu
Supposedly, I have 4 shards.
We're executing the above code 4 times.
yes, thats not a problem
Is it normal?
yes
I think what I should only remove is slashcommands.
that why you should not have any code in there that is not supposed to run multiple times, like creating slash commands
What else should not be ran multiple times?
running a webserver/dashboard for example
Quick question, how will I be able to prevent such file from running multiple times if I need to wait for index.js file to be ran (due to new Client())?
you remove it from there
how can I retry the function without it fulfilling?
async function proxy(q){
//stuff
if (!fastest) {
return setTimeout(async () => {
console.log("Retrying: All Rejected");
return await proxy(q);
}, 1000);
}
}
When would I be able to run it.

It's not like I can do something like node ./src/handlers/slashcommand.js && node ./src/shard.js. How would I be able to do it?
if(!fastest) {
await new Promise(r => setTimeout(r, 1000));
return proxy(q);
}
you are not understanding what im saying
im not talking about the handlers
im talking about the code that creates/sets a new command
ie sends the command information to discord
you only need to run that code when you create a new command or modify an existing command
it has nothing to do with the handlers
the handlers only receive the command and do something with it
keep all the handlers like they are, just remove the code that creates/sets the commands
when you need to create a new command or update an existing command, you create the code for that in a separate file and run that file separately one time only
and then update the handlers accordingly and restart the bot
Basically, I just add the .set() in another file and run it when needed.
you can use this for example
you dont need a discord Client to create commands
Quick question, <Client>.guilds.cache doesn't return all guilds, so this is why I would be fetching, so what could be the turn-around to this?
I'm setting the commands to a specific guild.
if you still want to use a Client, then client.application.commands.set(commands, guildID)
Yeah, but aren't all guilds cached?
If I go to a server on Shard ID 0 and type what!eval bot.guilds.cache.map(x => x.name);, it returns a different set than a server on Shard ID 1.
each shard has its own cache
i literally have no context about this but it just pops up every few minutes (im assuming its someone executing a command which is broken but i dont use discord buttons for this bot so i am so confused as to what its talking about) any ideas?
@quartz kindle sorry for ping, so like my bot is going offline in some servers but it’s working fine in others, it’s in 10k+ servers and there are 11 shards I’m not sure what’s happening. I checked logs there are no crash logs and I can also see 11 shards running 
Idk what to do

the error says that you are using discord-buttons
i mean i uninstalled discord buttons so idk
no idea, could be many things
What are some things I could try atleast
When I reboot the shards are fine
For like 6 - 7 hours

either you didnt uninstall it correctly or you have some other package that uses discord-buttons under the hood
log the debug event
you can hide the messages about heartbeats, since they are spammy
Hello everyone,
I tried to verify bot but it doesn't work.
What is the problem?
When the bot is started with the /start command... it creates two channels, one config and one join channel. The config channel is locked for the bot itself and the admin, so when I create a channel I add the condition to enter the channel you need to have bot permission or higher.
I find bot permission like this:
const myRoleId = guild.roles.cache.find(
(role) => role.name === process.env.BOT_ROLE_NAME
).id;
But for some reason on server they are testing, I can not find id of my bot role. (it's undefined)
Can someone help, thanks 🙂
is the bot role created automatically? did you setup its permissions in the invite url?
also, make sure your bot does respond with something useful in case the role is not found, instead of just crashing or becoming unresponsive
proper error messages and instructions are important for the bot to get verified
-htmldesc
You can achieve this using Markdown or HTML in your bot's description. You can ask in #development for help or use this HTML and Markdown cheatsheet for more resources.
visit the hyperlink and refer how to do that, if you need help further with that this channel is always an option
FetchError: maximum redirect reached at: https://www.instagram.com/miafitz/?__a=1&__d=dis i get this error when i try to fetch this url
but when I open the site in browser it outputs correctly
works fine for me
do your own projects and don't follow tutorials
you'll be stuck in tutorial hell and you won't learn much from them
idk your ideas
^
"in 3 hours" to understando how to make a hello world right?
in no fckin way u can understand js in 3 hours
well, start with a hello world program
then move on to a calculator
during the tutorial?
then do again
this time without a tutorial
Do not fall into tutorial hell
bruh i just yolo-ed into making a discord bot with no knowledge of js at all
worked kinda alright
You will know how to do a ton of useless things in different languages but you won’t actually understand anything about the language
try doing everything again but without the tuto
Make your own projects
Without tutorials
I'll give you some basic questions then
What is a string?
the thing cats play with
bruh
That is not what I asked
how to make a vote system?
WRONG
And what different ways can you make variables in javascript?
someone voted and receive moneeeey
u pushed to production, 34 emails from clients saying their server is dead
why? because var
Do not use var
var is the big nono
Unless you know exactly what you're doing
why?
Even then it should be avoided
i dont use it i just use let but idk why its bad
Because it hoists to the top of the function scope
var is hoisted, and gives no shits to its scope
oh i see
this gets way worse when you use libraries that also use var
b will be NaN
lol
token leak buddy
big funny
it wasn't fire
❌ Function $httpGet returned an error: HTTP GET returned an error: Get "https://normal-api.ml/topgg/hasvoted?bot=970724325491638303&user=905524360436125746&token=": x509: certificate is valid for *.parkingcrew.net, parkingcrew.net, not normal-api.ml
hello world -> calculator -> snake is my go-to project chain when learning a new language
try it
That's a pretty good method
Snake?
ye
it's pretty easy to make even on CLI-only
Another thing you could make is like a "school" where you have a student class, teacher class, class class, school class, etc. But I usually use that method for more object-oriented languages
Because you need to learn on your own by experimenting
object orientated stiff bends my brain in ways i dont like
Following tutorials is only going to assure that you know less
It doesn't change the fact that somebody else told you exactly how to write that code
u exceeded ur allowed bandwidth basically
You have to experiment on your own to learn
rip code of github anbd mash it with other code from github and then try and work out why nothings working
^^
no
lol
He was not serious
i mean its not about anything
Please please please do not copy code off of github if you're seriously wanting to learn anything
We told you like 15 times
depending on ur IDE u can also use ctrl + Q to read the docs without having to open a new window
Make your own project, try things out
and of course, use an IDE, no need to be hardcore and code in np++
If you are struggling with the basics, go back to some basic syntax tutorials online and try to apply that to your own project
i mean i copyed methods and commands of github before but never riped the whole thing in one cuz thats just uninventive
The only times I copy off of github is when I'm too lazy to write something tedious and I understand the code
ah yes, a thing that's very important regarding programming: do not try to learn the words, try to learn the "why"s and "how"s
half the stuff i find interesting is outdated anyway so i gotta write it from scratch anyway
I've had a few times where I look at somebody's github, then asked them what their thought process was before I copy it/modify it to my own project
it's not your job to write, it's your job to know where to write
For example, I was asking @lyric mountain about reflection for a forge mod I was writing, and looking at how he did it in his github for his discord bot
like the command i made to play my cassette player over discord was based on some code snipit from 2016 lol
That's when github is really handy, to figure things out by asking yourself "Why did this person write this the way they did?"
was compleatly borked
yeah
good to see the other ways of writing the same thing
ye, with github you can see real applications of certain methods or techniques
Exactly
don't see the code, see how they did and why they did
That small part of your reflection snippet helped a great deal with understanding how reflection works
Something that I had previously never done with Java before
Fair, I never ended up being able to use it anyways because the forge discord is toxic asf and half the people in there are "don't use old version" dickheads
but good that it worked for u, reflections are pretty easy once you get the concept
reminds me, i gotta make a command handeler for my test bot soon
its got almost 20 commands lol
But I did end up using reflection in a similar way for my C# recursive descent parser for math expressions
very scuffed though
But it's fine, the comment I left explains it all
lmao
I had to rewrite to include my custom syntax language
together with its parser
but really, I love how reflections allow finding code anywhere in the project
instead of having to declare paths and classes in a collection
so back to this, js barely has datatypes, no need to worry about it too much (for now)
Meh, I disagree on the worrying about it part
You need to know types
Before you can go typeless
😉
types = training wheels
Wrong
js isn't a good language to start with for that reason
Types make your life easier
training wheels do too, until you know what your doing. then they get in the way
Everything still has an underlying type regardless of how you see it
never had types getting in my way, usually it's the opposite since I can know what a value is by simply hovering on it
Yeah same
also makes life easier for the compiler
I personally like typescript because it guarantees that you're not responsible for making sure the types are correct when passed to your functions and other things
reflection is used to get around the type system
Not really no
Reflection bypasses the type system but it's because you may need information at runtime that is not available to you before runtime
Not because you want to make your code unsafe on purpose
reflection is basically doing runtime operations
instead of traditional compile-time
like injecting values, changing structure, attaching new classes, getting declarations, etc
For example in Java reflection is really useful for doing operations with classes with certain annotations and such
funny enough u can get the variable's name with that
i remember having to use reflection to write a unit test for a private method once
such a mess
Pretty sure there's a lot of testing frameworks that can do that for you but yeah
or just make it public for testing purposes
or make it protected and put the unit test in the same package
That's not what protected does
but the method should be private
No
protected means classes that inherit from that class can access it
if you put no access specifier on a class member in java it automatically becomes package access
isn't that protected?
i found it. it's called package private
class MyClass {
protected int myInt = 5;
int myPackageInt = 5;
}
class MySubClassNotInSamePackage extends MyClass {
// Can access myInt, but not myPackageInt
}
class SomeOtherClassInSamePackage {
// Can access myPackageInt, but not myInt
}
There's a keyword for it?
Interesting
the protected keyword is an access modifier for method and variable of a class. When a method or a variable is marked as protected, it can be accessed from: Within the enclosing class. Other classes in the same package as the enclosing class.
Is this part true for protected?
Other classes in the same package as the enclosing class.
Ok apparently that works
In my CS class we were taught that doesn't work
But apparently it does
maybe java change it
protected is broader than package-private
I think we just barely had the stream API so I'm pretty confident it was 8
private < package < protected < public
package being the default right?
package doesn't allow other classes in the same package to access?
what the diff between package and protected?
protected also allows subclasses
if u somehow extended a protected class from another package, it'd be able to access its methods
but since u can't (at least during compile-time), it works the same as package
ah, so it's only for runtime stuff? can't reflection bypass that all anyways?
reflection doesn't care about scopes at all
lol
u can access anything anytime, just need to setAccessible(true)
so let's say both package and protected are technically the same but conceptually different
interesting
then there are final and sealed classes lmao
but that's something I didn't understand fully yet
final is my favorite keyword in java
it's as rooted as rickroll into human history
types
not really
whatever runs the code will usually add it anyway during "compilation"
You should probably add them anyways, it’s better code style
oh, also remember that == (equals with typecasting) and === (equals)
watch out for stuff like this. js function whoops() { return { hello: "world" } }
function whoops() {
return {
hello: "world"
}
}
these two functions do different things
*sips coffee* js moment
So you can be more explicit in what you intend
(Or just use a linter that does it for you, like eslint or prettier)
Js is backend
I mean you could argue that it’s both but it’s a programming language designed for logic at its core
yeah it's backend
this should pass most linters. it's valid code
function whoops() {
return
{
hello: "world"
}
}```
Yes but the linters will add semicolons for you
So you can more easily see that you’re making a mistake
was thinking abt webpages, but that's technically html referencing js
gotcha
Thought you wanted to learn js
js doesn't need a domain
ye
domains are just for aesthetics
(and ssl)
js is just like any other language, u get something to execute it and simply run
usually u get node
your computer is the host
Js is most commonly found in the backends of websites, but the language’s use extends far beyond the scope of the web
to make something public
Because they want to host their website online to the public
you dont want to point a domain to your ip most likely
you wouldn't want to use your IP as the address
I think you’re losing sight of what js is lol
Javascript is a programming language
You can use it for many purposes
One of those common purposes is websites
But there are many more
You can make websites “public” by buying a domain name and pointing it to a host (such as a VPS) that serves all the content of your website to the client
use google domains
Yes, but I wouldn’t recommend purchasing anything until you already have your project ready to be put online
Since domain names are usually a yearly/monthly cost
But yeah there’s a lot of different sites
Usually they use a web framework of some sort, like React.js
vercel.com is a good host for react
Speaking of which I need to finish my portfolio and host it with vercel
React is frontend but also backend in a way
use sveltekit
Yeah that’s what I’m planning on
Svelte is a templating compiler isn’t it? Never used it before
Yeah
u can do anything with any programming lang really, the sky (and the computer) is the limit
nope
here's a sample
Depends on what you want to do in the future
If you want to develop websites for a living, then definitely
u can, which is what people call frontend devs (or fullstack when both back and front)
If you want to stick with backend stuff (Which in my opinion is where the real fun happens), then not really
In terms of employment? Not really. You won’t be earning much if anything from a discord bot
look around, there's a chance that there's at least one thing that involves programming in your sight
the lamp? yep, programming (the power grid)
Cybersecurity, lang dev, game dev, even rest api dev is pretty much its own thing now
So many options to choose from
Those are the specialties though
programming is the closest you get to being a god (in virtual world)
You don’t have to learn all about them
You can dive so far into one specialty and be a master of it
While not needing to know a ton about all the other fields
Probably just general backend development
I wouldn’t really put them in a category
it's really hard to comprehend how vast programming is
Usually it’s a good idea to dive into a few different fields and find something you like, and then master that one thing and learn a bit about all the other fields
And then master others if you find you enjoy them as well
I had, but scrapped it because I didn't like how it was done
There’s too much to learn for one lifetime however
can go from a couple dollars to thousands of dollars
Nothing. I’m just a student lol
java
My dream job would probably be to work on Roslyn
no, just java
Or maybe even work on a language with rust
that was long ago, doesn't mean much besides that I applied for verification at the beginning
But lang dev is definitely where I think I’m heading
that's a hard question
idk, maybe the fact that no matter how much knowledge I get there's always more to learn
I hate hitting a cap
I guess
Game dev also sounds kinda fun if I didn’t already know that most game companies suck to work for
Unity is pretty cool
Unreal is more beefy and scarier
I wanted to do professional game dev but...c++
A lot of games are also written in C# to be fair
c++? ohh yeah it is
Most AAA games use C++ and a custom engine though
Python is slow
Especially in the world of game dev
Where things need to be fast
python wasnt made for complex tasks really, it excels at doing small or repetitive tasks
C++ itself isn’t necessarily THAT hard, but debugging it is a nightmare
but u can do if u want, pretty much all VNs are made in python too
Plenty
Not that I know of
I’m sure there’s plenty of games out there made entirely in python, but it’s probably not a very complex game to be fair
visual novels
There’s some more complex stuff
idk other examples of games made with python
Unity is a good compromise between language complexity and speed, since it uses C# for the scripting
You can use any language for game dev
Some excel more than others at it though
C++ is the most popular game development language of choice
C# is probably 2nd
C++ is low level. C++ requires you to manage memory on your own, and has things like pointers and references. C# on the other hand is what’s called a garbage collected language, which basically means you don’t have to worry about manually managing memory. C# has references and pointers, but you don’t ever really directly work with them (aside from the occasional ref keyword) unless you’re doing some wonky stuff.
C++ is also very multi paradigm, but C# is mostly object oriented
Depends on what you want to do with it
C# has less complexity, but C++ is faster to run
If you need really really fast performance, C++ is the way to go
Definitely not C++
C++ will chew you up and spit you out; it does not hold your hand pretty much at all
After javascript I’d recommend probably Java or C#
Java and C# are very very similar
Java is pretty much C# with some differences
They’re probably relatively similar in terms of speed

Java is certainly the less complex option between the two
you mean C# is pretty much Java?!?!
cause java came before
c# is a ripoff of java
wtf
Microsoft likes to have “their” versions of languages they like to use
mh'
Like typescript
interface IExample {
name: string;
likes: number;
}```
// In javascript, a function that adds two numbers
function add(number1, number2) {
return number1 + number2
}
``` ```ts
// In typescript, a function that adds two numbers
function add(number1: number, number2: number) {
return number1 + number2;
}
Because technically in the first example, add("hello ", "world"); would produce the output of "hello world" even though you intended it to be used with two numbers, and not two strings
this too yeah
nice lang
Whereas in typescript doing that would fail before the program even runs, because it knows that you want two numbers to be passed into the function instead
Thanks for asking questions C:
Nope. I love computer science so I’m happy to answer questions
Are in uni in CS?
It's was actually attested that java comes really close to c++ performance after JIT kicks in
I’m sure in some scenarios yeah
Partly because java is to bytecode what c++ is to assembly too
But the garbage collector is the main reason for the performance gap at this point
Yeah, there's that
Granted a garbage collector is much better than a memory leak, so better be good with C++!
Ohno fatorial, now u created C++++
Lol
/r/unexpectedfactorial

Its offline
Thats kinda funny tho
I thought u guys gonna help me
They are asking you what it is
you arent providing any informastion we can use
That's not the information they are asking for.
Me?
Yes...?
Idk where i can find the coding yet
You need to create code for your computer/host to run, then your bot will come online and start responding to whatever you give it
function add<T extends Monoid>(a: T, b: T): T {
return a + b
}
maybe one day
Does that not work?
Am dead
I don't think you can define a monoid in typescript
what's a monoid
Does anyone know how to setup Recaptcha on a website?
@everyone t
how can i check permission for a user in slash command
Depends on the library you are using but the Discord API User object includes a permission Array if I remember correctly.
What library are you using?
for slash cmd
For the bot
.js
That's a lang
.js 👍
Ok
@fallen holly Ok so you could check permissions with GuildMember#permissionsIn(BaseChannel) which gives you the current permissions of said user for a defined channel.
I hope this helps 😉
B
Hi so, if I see interaction failed errors does that count as getting blocked temporarily?
also just a quick question, if the bot is in 10200 servers, does the last shard handle 1.2k servers?
cause its only spawning 10 shards
Shards can handle up to 2000 guilds each
Hey, I just wanted to know how can i host my bot made with typescript cuz i can't find a way to host in heroku. if you could help that would be great ty <33
How do I fetch this one? Using
const check = con.findOne({
memberID: Array
})
const listing = check.members
return console.log(listing)
``` return as undefined tho
you can indeed host it on heroku
just need some skill
:< can you help with that?
what's your start script rn?
ts-node src/index.ts
yes
use that
ts-node was never made for production
at least that's what I remember
make your start script something like
tsc && node . (Guessing you configured it right)
in tsconfig
so something like
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"rootDir": "src",
"declaration": true,
"outDir": "build",
"removeComments": true,
"newLine": "crlf",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"skipLibCheck": true
}
}
and in package.json put
"main": "./build/main.js",
yep fixed
how to do increasing number effect
number += 1
you using react?
just use a setInterval
That uptime tho xD
I was gonna tell to use number as state then use setinterval
next.js
that's pretty much the same
set count as state
create a setInterval
and do something like (if number > count) (count ++)
display count
done
ohh alright
Here is a way done using classes: https://codepen.io/aziziraheem/pen/eYOGByQ
Should be simple to migrate to a functional component if needed
I mean for a few seconds yes
It will defo re-render a lot. If you dont have like hundreds of counters, it should be fine
Oh yeah, that was a bad example
Hello everyone,
I tried to verify bot but it doesn't work.
What is the problem?
When the bot is started with the /start command... it creates two channels, one config and one join channel. The config channel is locked for the bot itself and the admin, so when I create a channel I add the condition to enter the channel you need to have bot permission or higher.
I find bot permission like this:
const myRoleId = guild.roles.cache.find(
(role) => role.name === process.env.BOT_ROLE_NAME
).id;
But for some reason on server they are testing, I can not find id of my bot role. (it's undefined)
Can someone help, thanks 🙂
Role for bot is auto created on invite?
They probably invite the bot with no permissions and roles
and after doing a little search I found it was already explained to you by vision
Yeah, but how should I create bot role?
why would you need bot role anyway?
<guild>.roles.create()
Because I am creating thread (config) which is locked for bot and admins...
idk which language / library you're using
Typescript, DiscordX, DiscordJS
<Guild>.roles.create()
Okay, thanks!
Anyone knows how to fetch the array without any other string? using the _id is not working, yep didnt work earlier
I have an array of settled promises, half of them are fulfilled, half of them are rejected. How can I filter out the rejected ones? I could do Math.random() < 0.5;, but that's just dumb
is there a way to detect when someone replies to a bot?
like this version of reply
TypeError: Cannot read properties of undefined (reading 'send')
you can do fetchReference and then that message's author's id
https://discord.js.org/#/docs/discord.js/main/class/Message?scrollTo=fetchReference



