#development

1 messages · Page 186 of 1

past field
#

the slash commands that i have so far work well

#

but I was wanting to also have my bot automatically respond in certain moments

#

like, how can i have my bot send a message when a new member joins the server

sharp geyser
#

Like not based off any user interaction?

#

Oh, so you'd use events.

past field
#

i was reading that

#

and i tried to add it based on what i was reading but i guess i was doing it incorrectly

#

again, i’m very new so sorry if im asking for too much

sharp geyser
#

if you are using discord.js they help you by attaching all these events to the client class.
so say you have this setup:

const client = new Client();

client.on("guildMemberAdd", (member) => {
  // do something when the member joins
});

client.login("bot token");

this is a simple way to do it

#

You can listen for any events by using on method on the client

#

Note, some events do require priveledged intents to use them fully

past field
#

that was what i was currently trying to understand

#

i didn’t know what “intents” were

sharp geyser
#

Ah, so basically they just tell discord what data or events you are wanting to receive from them.

past field
#

ohh ok. when i was setting up the application in the portal, there were some “intent” options on there, I just skipped it until i learned what they did

green kestrel
#

think of intents like choices in a menu at a restaurant

sharp geyser
#

It used to be you never had to tell discord what intents you wanted to give them, by default they just gave you everything. But ofc that was not correct so now they have you specify it.

green kestrel
#

you place your order (set intents)
waiters bring that food (discord delivers events)

past field
#

ok i’m following

green kestrel
#

if you didn't order it you don't get it

past field
#

okay i gotcha

sharp geyser
#

Those are the "higher costing items" to use brain's anology

past field
#

so i should go back into the portable and enable them?

sharp geyser
#

Nope

#

Unless you need them.

past field
#

oh

#

For reference - I’m making a custom bot for just my server only

#

for now at least

sharp geyser
#

Thats fine :D

past field
#

so to set an intent to do something like sending a message to my mod channel when a new member joins, how would i set that intent?

sharp geyser
#

Well, first off you'd need to set the GuildMembers intent. This allows you to receive the appropriate events.

past field
#

and i’d have to modify discord.js to do that?

pale vessel
#

yes, u also need to set the intents for ur client while connecting

sharp geyser
#

that can be done with

const {Client, IntentsBitField} = require("discord.js")

const { GuildMembers } = IntentsBitField.Flags;

const client = new Client({
  intents: [GuildMembers]
})

client.login("bot token")
pale vessel
#

it's a bit weird for privileged intents but the toggles on the portal are for allowing your bot to use the privileged intents

sharp geyser
#

Also you will need to enable this in the bot portal:

#

As the GuildMembers intent is a privileged one.

past field
#

ok let me do this now

sharp geyser
#

Almost everything can be destructured in js (iirc)

past field
#

ok gotcha

sharp geyser
#

someone back me up on this I haven't used js in ages

past field
sharp geyser
#

well, if you haven't split your code into multiple files then in your main file

past field
#

oh lord

sharp geyser
#

I assume you haven't since you started 2 days ago

#

creating modules will be a challenge for someone who just started EYES

past field
sharp geyser
#

oh no thats node_modules those are the packages you install aha

sharp geyser
#

yea so what does your file structure look like I wonder

past field
#

for the commands?

sharp geyser
#

for your project

past field
#

If that's what you mean

sharp geyser
#

oh cool you do seperate your commands into other files

#

good

#

organization is key to keep a sane mind

past field
#

oh yes i need them all separated lol

sharp geyser
#

anyway, you'd likely do all your events in the index.js for now until you can separate those as well

#

just modify your client to take in the GuildMembers intent

#

and then client.on("guildMemberAdd") or whatever event you want to use

#

a useful tool to learn discord.js is the docs as well

past field
sharp geyser
#

essentially all events will work the same

#
client.on("eventName", (args) => {})
#

replace eventName with the name you want to listen to

#

and args with the properties the event gives

#

if it gives multiple do client.on("eventName", (arg1, arg2, arg3) => {})

past field
#

okay so

#

I can skip line 58 and add it starting on line 59?

sharp geyser
#

yup

#

doesn't matter where you put the event listener

#

so long as client is defined

past field
#

@sharp geyser You're about to hate me

sharp geyser
#

Whats up

sharp geyser
#

okay so essentially yes, you just modify your current client tho

#

also you don't HAVE to do it how I do

#

its just how i'd recommend

past field
#

ok so

#

how do you send it as a copy-able code like that

sharp geyser
#

you mean highlighted?

past field
#

yes

sharp geyser
#

oh thats simple

#

discord allows code highlighting

#
console.log("Hello, World")
past field
#

mine shows as plain text lol

sharp geyser
#

you need to include the highlight symbol js in this case

past field
#

js

#

const { GUILD_MEMBERS } = Intents.FLAGS;

const client = new Client({
  intents: [GUILD_MEMBERS]
});

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('guildMemberAdd', member => {
  // This is the channel ID where you want to send the welcome message
  const channelId = 'your_channel_id_here';
  
  const channel = member.guild.channels.cache.get(channelId);
  if (!channel) return; // Channel not found, do nothing
  
  channel.send(`Welcome to the server, ${member.user}!`);
});

client.login("bot token");
sharp geyser
#

its important to use 3 open ticks and 3 closing ticks

#
const { Client, Intents } = require("discord.js");

const { GUILD_MEMBERS } = Intents.FLAGS;

const client = new Client({
  intents: [GUILD_MEMBERS]
});

client.on('ready', () => {
  console.log(Logged in as ${client.user.tag}!);
});

client.on('guildMemberAdd', member => {
  // This is the channel ID where you want to send the welcome message
  const channelId = 'your_channel_id_here';
  
  const channel = member.guild.channels.cache.get(channelId);
  if (!channel) return; // Channel not found, do nothing
  
  channel.send(Welcome to the server, ${member.user}!);
});

client.login("bot token");
past field
#

Oh i see ok

sharp geyser
#

yea

#

also if you want it highlighted

#

directly after the 3 first ticks, include the highlighting symbol

#

which in this case would be js

past field
#

ok gotcha

past field
sharp geyser
#

yea

#

assuming the channel is in cache

#

which iirc channels are always cached

past field
#

ok so im adding this to index.js

winged linden
#

I have a question, i wanna start sharding really soon but how will i be able to manage an express app linked to my bot? How will i fetch specific data from a specific guild?

sharp geyser
winged linden
#

Wanna start sharding soon

sharp geyser
#

Does your bot need it?

winged linden
#

And my functions are resourse intensive

#

So yes i need it

quartz kindle
#

ie:
shard manager
v
-> shard1
-> shard2
-> shard3
-> shard4

#

the shard manager can communicate with the shards, and individual shards can communicate with the manager

#

shards can also communicate with other shards through the manager, also known as broadcasting

#

you can run webapps on the manager process

#

requests to the webapp can be broadcast to shards from the manager

#

ie:
webapp receives request for a specific guild > manager requests data from shard > shard returns guild data > webapp responds with guild data

sage bobcat
#

One message removed from a suspended account.

quartz kindle
#

:3

past field
pale vessel
#

the programming language (for instance js or javascript, both work)

past field
#

ok gotcha

winged linden
sharp geyser
past field
#

@sharp geyser

#

you taught me so much about event thank you!

#

so I have something I want to try and I think i know what to do based on what i’ve been reading and based on what you helped me with

#

if i wanted the bot to auto respond to lets say cryingmo emoji

#

like whenever someone uses it, the bot auto responds with a joke of some sort

#

i would enable the “message content” intent?

sharp geyser
#

yep precisely

past field
#

ok gotcha

#

how does this look

#
client.on('message', message => {
    // Check if the message contains the specified emoji
    if (message.content.includes(':cryingmo:')) {
        // Respond with a random joke about being sad
        const jokes = [
            "Why did the scarecrow win an award? Because he was outstanding in his field!",
            "Why don't scientists trust atoms? Because they make up everything!",
            "Why couldn't the bicycle stand up by itself? It was two-tired!",
            // Add more jokes here
        ];

        const randomJoke = jokes[Math.floor(Math.random() * jokes.length)];
        message.channel.send(randomJoke);
    }
});```
sharp geyser
#

I honestly dont remember if you can handle emotes like that

#

so its best to test it out and see

#

if it doesn't work come back

deft wolf
#

Also messageCreate instead of message in client.on

#

This was changed in v13 if I remember correctly

sharp geyser
#

real question is what version are they using EYES

deft wolf
#

14

sharp geyser
#

hopefully the latest

#

but who knows

#

oh right NyNu you are helping them as well

past field
#

nynu is a discord bot coding god in my eyes

sharp geyser
#

theres the image

#

use it how you want

past field
#

one of the most patient persons i’ve ever communicated with in my life

past field
past field
#

success 🙌🏾🙌🏾🙌🏾

#

thank you @sharp geyser @deft wolf

past field
deft wolf
#

Congratulations peepoPOGGIES

past field
#

ok another question

#

is there a way for me to code my ban command to ban a user by ID that is not in the server?

#

i have a bot that i use to do that but I want to be able to learn how to do that with my custom bot

#

this is my ban command code

#
const { Permissions, TextChannel } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('ban')
        .setDescription('Bans a user')
        .addStringOption(option => option.setName('user').setDescription('The user to ban (mention or ID)').setRequired(true))
        .addStringOption(option => option.setName('reason').setDescription('Reason for the ban').setRequired(true))
        .toJSON(),
    async execute(interaction) {
        // Check if the user has the necessary permissions to ban members
        if (!interaction.member.permissions.has(Permissions.FLAGS.BAN_MEMBERS)) {
            return interaction.reply({ content: "You don't have permission to ban members.", ephemeral: true });
        }

        // Get the user from the command options
        const userOption = interaction.options.getString('user');
        const user = interaction.guild.members.cache.find(member => member.user.id === userOption || member.toString() === userOption);

        // Check if a valid user was found
        if (!user) {
            return interaction.reply({ content: "Please specify a valid user to ban.", ephemeral: true });
        }

        // Get the ban reason
        const reason = interaction.options.getString('reason');

        // Attempt to ban the user
        try {
            await interaction.guild.members.ban(user, { reason });

            // Prepare information to post in the specified channel
            const channel = interaction.client.channels.cache.get('1179382116077809714');
            if (channel instanceof TextChannel) {
                await channel.send(`Banned User Information:\n- Discord Name: ${user.user.tag}\n- Discord User ID: ${user.user.id}\n- Reason for Ban: ${reason}`);
            } else {
                console.error("Failed to send ban information. Channel is not a TextChannel.");
            }

            return interaction.reply({ content: `${user.user.tag} has been banned.`, ephemeral: true });
        } catch (error) {
            console.error(error);
            return interaction.reply({ content: 'There was an error while banning the user.', ephemeral: true });
        }
    }
}```
deft wolf
#

I think the only option to ban a user by id (considering that you have never seen this user) is to use guild.bans.create(userId)

#

I've never used it personally, but it's probably what you're looking for

sharp geyser
#

Which means that if they have not shared a server with the bot, then they can't be banned

#

Best thing you can do is ban them when they join

#

Which just requires you to have their id and just put that in an array of blacklisted ids that get queried when a person joins. if their id matches any in the array automatically ban them

deft wolf
#

All these moderation bots must have a very difficult time working because of this cache, and people continue to create more moderation bots kappalul

past field
#

Ah ok I gotcha

past field
#

ok another question

#

nvm ignore me

runic relic
#

Just want to ask regarding it is worth it to switch from discordpy to discordjs?
I feel that my bot have a bit slight slow response compare to other bot...

sage bobcat
#

One message removed from a suspended account.

#

One message removed from a suspended account.

runic relic
#

i see

sage bobcat
#

One message removed from a suspended account.

solemn latch
#

It might be helpful to do some basic performance checking to determine if it's actual bot performance issues or just a latency issue.

sage bobcat
#

One message removed from a suspended account.

green kestrel
sharp geyser
#

when you call .create it checks for the ID in the users cache, if it doesn't exist it throws an error

#

actually wait

#

I might of misread this when tired

green kestrel
#

why, if it takes an id

#

that seems weird

sharp geyser
#

yea no it seems to rely on the cache

sharp geyser
#

I might be misreading the source code

deft wolf
#

I need to try this

sharp geyser
#

but it does make calls to the cache manager

#

which I can only assume will check the cache for the user

#

Following the rabbit hole

#

this.client.users.resolveId

#

Now lets assume the user does indeed not share any server with the bot, none of those checks will even remotely check out

#

so it will call super.resolveId

deft wolf
sharp geyser
#

now UserManager extends CachedManager which extends DataManager which finally has this resolveId method

green kestrel
#

this is weird, if you have an id you don't need cache

#

that's how discord API works

sharp geyser
#

now as NyNu seems to point out it does still work

#

which leads me to believe its not actually relying on cache, but for some reason the methods they have to check its a valid id or whatever exists on the CacheManager or whatever CacheManager extends which is whatever that extends

#

😔

deft wolf
#

Typical discord.js moment Classic

sharp geyser
#

Djs code base is basically 1 class extends another, which that class then extends another and that class also extends another

#

By the end of it 1 class has 4 extensions

#

not even kidding you

#

GuildBanManager extends CachedManager extends DataManager extends BaseManager

#

BaseManager is literally just a class that defines client

#

💀

sharp geyser
#

im surprised anyone can commit to it

radiant kraken
harsh nova
#

Don't forget how half the features get deprecated from one version to the next

green kestrel
sharp geyser
#

I wish there was a better alternative for js developers

#

but djs is just too deeprooted

green kestrel
#

there is - move to a better language

#

I recommend C++ or rust

sharp geyser
radiant kraken
#

what does the implementation language have to do with it

lament rock
#

Now I dont mean to self advertise - but using libs that interact with the raw api like SnowTransfer and CloudStorm are literally amazing

green kestrel
sharp geyser
#

Im starting to pick up go myself tho I still dk if I want to use go or rust for my api

green kestrel
#

what is the state of libs for go

sharp geyser
#

dk yet

radiant kraken
#

discordgo ig

green kestrel
#

disgo seems more up to date

lament rock
#

steer away from managed libraries

green kestrel
#

it's also the only one using API 10

sharp geyser
#

idk I feel like go's reliablity when it comes to building an api is better, but rust is also so nice in its own way

#

I will think about programming language later tho

green kestrel
#

discord is one of those weird things where it's very much a thing to choose your language based on the quality and maintained state of its discord libs

#

only that could explain why so many dpp users these days lol

lament rock
#

If you interact with the raw api, not really

#

the vertically integrated libs all mostly suck

green kestrel
#

if you must interact with raw API the lib is missing features

lament rock
#

One of the main reasons I stick with node and really can get great cpu and memory stats is because of proactively removing bloat

green kestrel
#

and if it's easier to interact with raw API than use the lib the features are badly made (d.js)

lament rock
green kestrel
#

do you enjoy reinventing wheels then?

lament rock
#

You're yet to give me an example

green kestrel
#

if you're doing raw API calls how do you deal with rate limits

sharp geyser
#

I see no problem with wanting to interact with the api in your own way.

lament rock
#

That is included in the lib I mentioned and maintain lol. Just raw dogging fetch isnt the way

sharp geyser
#

Technically every lib is just reinventing the wheel in their own language

lament rock
#

Implementing rate limiting is trivial though so that's such a weird example

green kestrel
#

in C++ all other wheels were broken or square

green kestrel
lament rock
#

It is quite trivial to me

#

Though I guess it depends on your architecture sure

green kestrel
#

what the fuck my phone tries to play .TS as a video

lament rock
#

There are ts videos

green kestrel
#

this ain't one

#

mimetypes OnePlus use them

lament rock
#

Cringe

#

this isnt even the raw github

green kestrel
sharp geyser
#

isn't it purely a rest client?

#

there is no shards

lament rock
#

This is just a rest client

sharp geyser
#

CloudStorm is the gateway client

#

i assume

lament rock
#

yea

green kestrel
#

so there's only ever one of this acting as a proxy

#

yes?

lament rock
#

You can daisy chain proxy

#

or spread the proxy if you have a special way to get bucket info

green kestrel
#

just wondering how different shards share global rate limit info

#

if you had cloudstorm doing sharding

lament rock
#

cloud uses snow for get /gateway/bot so you can pass a modified snow instance that has refs to the proxy

radiant kraken
sharp geyser
#

its just which is more appropriate for my use case thonk

radiant kraken
#

what's your use case?

sharp geyser
#

hm well, i'd rather not get into that here as its personal but I can dm you about it

radiant kraken
#

sure

eternal osprey
#
20|Koopapi  | Error: listen EADDRINUSE: address already in use :::4434
20|Koopapi  |     at Server.setupListenHandle [as _listen2] (node:net:1751:16)
20|Koopapi  |     at listenInCluster (node:net:1799:12)
20|Koopapi  |     at Server.listen (node:net:1887:7)
20|Koopapi  |     at Object.<anonymous> (/root/site/koop.js:640:13)
20|Koopapi  |     at Module._compile (node:internal/modules/cjs/loader:1256:14)
20|Koopapi  |     at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
20|Koopapi  |     at Module.load (node:internal/modules/cjs/loader:1119:32)
20|Koopapi  |     at Module._load (node:internal/modules/cjs/loader:960:12)
20|Koopapi  |     at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
20|Koopapi  |     at Module._compile (node:internal/modules/cjs/loader:1256:14) {
20|Koopapi  |   code: 'EADDRINUSE',
20|Koopapi  |   errno: -98,
20|Koopapi  |   syscall: 'listen',
20|Koopapi  |   address: '::',
20|Koopapi  |   port: 4434
20|Koopapi  | }```
#

i already tried finding the process and using kill pid

#

but port is still in use..?

#

how can i fix that

green kestrel
#

by waiting

#

when you close a port of you don't close it properly e.g. you kill the process the port changes to FIN_WAIT state and can stay open in that state for ages, like minutes

#

it's to stop a new process immediately sniping the port, it's a security feature

#

it's basically because TCP expects a proper close() to be a 2 way thing like connecting

eternal osprey
#

i see

#

thank you!

#

Each day a new day to learn ig!

#

are you sure it won't take hours/days of waiting?

#

cuz then i'll just switch to an alternative https port

green kestrel
#

no 6 mins 45 secs apparently

#

or a reboot

#

if it takes longer you got a process still open somewhere

eternal osprey
#

yeah i used the lsof with root access and it showed no open processes though

#

so ig we just wait 🙂

eternal osprey
#

also another question

eternal osprey
#

root@awsomecordServices:~/site# sudo netstat -tuln | grep 4434
root@awsomecordServices:~/site#

#

though it still says port already used...

#

root@awsomecordServices:~/site# ps aux | grep Z
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1030251 0.0 0.0 8900 732 pts/1 S+ 13:10 0:00 grep --color=auto Z

#

aha

#

it became a zombie process

#

what the fuck can i do

past field
deft wolf
#

No, I used my eval just to check how this function works

past field
#

ohh ok gotcha

past field
#

is anyone here and have some time to help me out with something 👀

pale vessel
#

it's better to just ask so that anybody could just answer if they saw

past field
#

true

#

I’m just trying to move my project over from my macbook pro to my windows pc desktop

#

writing a discord bot with discord.js slashcommandbuilder in virtual studio code

#

i uploaded the entire project folder onto google drive and downloaded it to the desktop on my pc

#

installed node

wheat mesa
#

yeah no you can't do that

pale vessel
#

is there any reason u don't use git?

wheat mesa
#

just copy all of the files without node_modules

#

Then run npm i in the command line

#

and yeah ideally you should use git but if this is just a fun project then it's probably not fully necessary

past field
#

so if i download the files to my pc desktop, can i just delete the node modules

#

& im creating a custom bot for just my server

wheat mesa
#

yes, then when you run npm i, it'll install the proper node modules you need

past field
#

and i’d have to re-create the .env file? cause i don’t see where it copied that file

wheat mesa
#

I mean if you used an env file and didn't copy it over then yeah

past field
#

ok i’ll try this really quickly

past field
past field
#

ok got it going!

#

thank the lord

lament rock
#

You can load env files into node using dotenv

#

and you just transfer your env file to whatever server you want

#

gdrive isnt a good place since people have found ways to bypass google 2fa last I heard

#

And plus having a secure server you login with private public key pairs means hackers can get on unless they have your private key which means physical machine or they take the files off your machine and know where the keys go to.

spark pebble
#

Does anybody have any feedback if this would be consdereed a privacy concern?

#

specifically the guild name part of course

#

For those who can't be bothered to read (dont blame you)

  • card collecting game, when somebody claims a card that is of the super duper rare rarity, it announces it in our "hub" discord.

is it a privacy concern to say "@user claimed a cursed card >> in guild_name << ??

lament rock
#

Yeah do not post guild names in other guilds unless its for your eyes only

#

Just say that a user claimed it

lyric mountain
#

sudo kill -9 1030251

past field
#

anyone have experience with SQlite?

neon leaf
past field
#

what should I do to get the bot to recognize button interactions?

#

is that considered an event that needs to be added to the index.js? or is that something in the actual code that i need to add?

craggy pine
#

Buttons are a collector. And you do a .on('collect') event and check the condition when clicked on.

sterile lantern
eternal osprey
#

@green kestrel i have finally finished the tcp parser

#

listen i was struggling

#

like fr

#

using this protocol i could make it happen

#

i used this Go Back N, i basically setup a connection in the form of a window and kepy sending packets until the queue was full. I then labeled each sent packet, and waited until i received an acknowledgement. iF IT WAS duplicate, it means it wasn't received properly and i resent all the packets. Hardest part was figuring out how to delete all received packets if a duplicate was found at the receiving end (as the will receive all packets again anyways, hence i had to try to be efficient).
I thought first, maybe i can just resend the 1 failed packet. But if one packet errored we have no guarantee that the rest of the packets will be sent properly, nor will the output be sorted. I could maybe have sorted it receivingend

past field
eternal osprey
#

all i am saying

earnest phoenix
#

J’ai votre adresse

eternal osprey
#

you have my adress i really don't care

#

i know my adress already

earnest phoenix
eternal osprey
#

i ain't reading allat, happy birthday though ^0^

earnest phoenix
past field
earnest phoenix
real rose
#

@pliant gorge

earnest phoenix
#

they r definitely in a basement

real rose
#

ok

earnest phoenix
#

there gotta be a high rank

past field
past field
eternal osprey
past field
#

random

real rose
#

i saw that

eternal osprey
#

hey guys, what price is an ecommerce website usually?

earnest phoenix
real rose
#

high enough if its fully fledged and fully custom

eternal osprey
#

it has payments using stripe, good assortiment with products, emailing system.

#

what would be the minimum for such sites.

#

would the range be 700$>?

earnest phoenix
#

I offer a bread slice

earnest phoenix
real rose
#

-m @earnest phoenix idk what you're doing here, but you're speedrunning a ban here. Gonna slow you down for a bit | 3h

gilded plankBOT
#

upvote happybaka#0 was successfully muted

real rose
#

bro just trolling

eternal osprey
#

she's in that life phase where she tryna be funny for validation

real rose
#

really thought they were doing msth

past field
#

thank god you muted

past field
sharp geyser
#

@wheat mesa Low Level Learning's video on switch statements is so confusing ahhhhhhhhh

past field
#

ok so if i’m understanding correctly

#

i need to add an event listener to my index.js for button interactions

#

create the buttons in the /command.js code

#

send the buttons in a message

#

and add handle button interaction in the event listener that i put in my index.js file?

sharp geyser
#

yep

#

though djs has a way to do that in your code as well if you wanted.

#

You don't necessarily need to do an event listener for it

past field
#

will that be easier?

sharp geyser
#

yes

past field
sharp geyser
#

If you do it in your command code you can handle the data you need in the code itself.

#

you can also disconnect the handler anytime you want

#

let me find the docs for it

#

I haven't done this in a while

past field
#

okay

sharp geyser
#

yea so it seems you can use InteractionCollector

past field
#

lord

sharp geyser
#

essentially its just

const { InteractionCollector, Client, ComponentType } = require('discord.js')

const client = new Client({intents:["WhateverIntents"]})

const collector = new InteractionCollector(client, {
  componentType: ComponentType.Button,
  interactionResponse: the interaction
})

collector.collect((interaction) => {
  // do something with the button
})
#

at least I think, based off the docs

#

actually wait

#

there might be an easier way

#

This is one method, it just gives you more control over the collector

sharp geyser
#

It allows you to do it based off the interaction response without the need of using InteractionCollector, unless you need find control over where to use the collector in case you need to do so in a specific guild, channel or on a specific message

past field
#

i might be able to see what you mean better in real time

#

no offense if you say no lol i know that’s a lot to ask

sharp geyser
past field
sharp geyser
#

idk about the validity of the functions, but that seems correct in handling button interactions

sharp geyser
#

you make no definition for that

past field
#

ah

#

that is suppose to display in the embed whose turn it currently is and only let that player play the turn

sharp geyser
#

yes but the thing is

#

currentPlayer is simply nothing

#

it isn't defined

#

at least not in this code, and you don't import anything about it either

past field
#

ah

#

ok i see

#

hm

past field
sharp geyser
#

well you just define the person's whos move it is

#

typical rules of tic tac toe is X goes first

#

whoever is X set them to be the current player. then when they make their move set the currentPlayer to be the other person.

past field
#

ohhhh ok i got you

#

OH

#

ok i get it

past field
sterile lantern
#

discord requires a response within 3 seconds

#

you could send an ephemeral message saying that their move was recorded

#

for reference this is what a ephemeral response looks like

past field
#

ah

#

ok i gotcha

sharp geyser
#

but yea what sam said

#

each button is also considered an interaction. So you have to do something when its actioned

#

You can either defer the reply and edit it later, or respond to it immediately

#

Also one thing i'd do is send an ephemeral message to the other player when its their turn

#

that way you are doing something and notifying them

past field
#

ahhhh ok got it

past field
past field
#

@sterile lantern thank you so much as well

sterile lantern
#

np

#

I recommend you watch some tutorials on discord js as they definitely helped me understand how it works a lot better

#

It’s nice to have someone explain it to you step by step haha

crystal wigeon
#

whatis wrong with topgg?

#

people are not able to vote for the bot

#

its been like this like amost everyday

desert urchin
#

@warm surge

crystal wigeon
deft wolf
thorny cargo
#

So I am having issues with my db

Error

MongooseError: Operation `autodeletes.findOne()` buffering timed out after 10000ms at Timeout.<anonymous> (C:\Users\alban\documents\github\autodelete-v14\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:186:23) at listOnTimeout (node:internal/timers:573:17) at process.processTimers (node:internal/timers:514:7)

What I've done after research :

  • Restart my vps 🤡
  • Give access to my IP separately than just have the 0.0.0.0
  • Try to connect via compass and check if there is any issues (no issues)
  • Try to find different ways to connect but nothing seemed to do anything.

Right now, I am using mongoose on node.js , I havent touched the code for a while and this cam up yesterday, as a result my app will not work.

frosty gale
#

im not sure what buffering means in this context

#

mongodb terminology

#

you can do findone queries normally in other places though?

#

@thorny cargo sounds like you just need to do an await on your model connection or something of that sort

thorny cargo
# frosty gale <@453370780387115019> sounds like you just need to do an await on your model con...
 async connect() {
    if (mongoose.connection.readyState === 0) {
      try {
        console.log(`${ChalkAdvanced.blue('Database: ')} ${ChalkAdvanced.gray('>')} ${ChalkAdvanced.yellow('connecting...')}`);
        await mongoose.connect(mongoUrl)
        if (mongoose.connection.readyState === 1){
        console.log(`${ChalkAdvanced.blue('Database: ')} ${ChalkAdvanced.gray('>')} ${ChalkAdvanced.green('Successfully connected')}`);
      } else {
        console.log(`STATE OF THE DB HEREEEEEEEEEEEE : ${mongoose.connection.readyState}`)
      } 
      } catch (err) {
        console.error(err);
      }
    } else {
      console.log('Already connected to database.');
    }
  }```
so the connection is successful in the end, thats why it gets me confused , even tho it connects, it doesnt work, and it throws me those errors
hoary apex
#

guys what intents must be given to a chat bot??

pale vessel
#

privileged intents? message content

deft wolf
#

The ones your bot will need

pale vessel
#

although if u use slash commands u don't need that

crude totem
#

whos managing the top.gg python library

#

can we exclude discord.py from pip because theres many other good libraries out there and discord.py isnt the one always being sued

stuck pewter
#

help why i get this error :

#

could someone help?

deft wolf
# stuck pewter could someone help?

But what should we help you with? This is an error that usually means that your bot took more than 3 seconds to respond to the interaction

#

Either your bot is terribly optimized or it performs a database query or some other action that takes more than 3 seconds

stuck pewter
deft wolf
#

You use fetch in your command which pretty much means directly querying the api (if guild and channel are not in the cache). The best solution would be to use .deferReply() first and then .editReply() instead of .reply()

#

Also your interaction handler violates discord's developer guidelines. Your bot cannot create an invitation to the user's server without the user's knowledge. This is considered a privacy breach

harsh nova
#

^ we deny bots for doing that if we find them during testing and ban if we find it after the bot has been approved unless mentioned in the privacy policy

#

I strongly recomend not doing that

stuck pewter
harsh nova
stuck pewter
#

got it! ty

sterile lantern
#

what type of option is this called

#

oh wait i can put choices for string nvm

past field
#

ok question

#

let’s say i have my tic tac toe game set up to send an ephemeral after each turn - to have a response to the interaction button. instead of sending a new ephemeral everytime, i want it to just edit whose turn it is in the ephemeral.. would that edit be considered a response to the button interaction of the game?

#

this is what the game looks like for reference

pale vessel
#

you'd have to save the message/message id of the first ephemeral response and edit that instead on later turns

#

assuming they don't dismiss that one ephemeral response though

sterile lantern
#

you could probably have a regular msg (non-ephemeral) that edits each time

#

but im not quite sure if that counts as a 'response' to an interaction

spark flint
#

you dont have to send a reply

#

you can defer button update

#

which would prevent the need to send an empheral response every time

sterile lantern
spark flint
#

nope

sterile lantern
#

really?

spark flint
#

yes

sterile lantern
#

oh wait that makes sense

#

you can just edit the msg

spark flint
#

for discord.js, its js await <ButtonInteraction>.deferUpdate()

#

then you can edit yeah

sterile lantern
#

lol i have that rn facepalm

#

defers cmd, then just edits the original reply

spark flint
zinc plume
deft wolf
#

Do I understand correctly that your bot creates a channel only to set up a ticket system there?

#

And then deletes it?

craggy pine
spark flint
#

await just means it waits for that action to finish first

#

in some conditions it can cause a broken race condition

#

for example, ```js
interaction.deferUpdate()

// maybe edit msg or smth
message.edit(/something/)

interaction.edit(/something/)```

#

it can cause errors saing interaction already deferred etc

craggy pine
#

In my cases my deferUpdates are used mainly to do a function without directly replying to the user back but also letting them know the button press worked.

spark flint
#

thats fair

#

i dont think it would matter too much in your case

craggy pine
#

I assumed so. Thanks for the insite.

spark flint
#

i just await stuff by default at this point lmfao

sterile lantern
#

lol same

zinc plume
past field
#

Ok so I’ve decided to dedicate myself to creating a bingo game… I started today with simple creating button interactions for people to join the lobby and for the host the start the game and cancel the game

pseudo grotto
past field
#

this is the code, if anyone has a moment to look over it and tell me what I’m doing wrong 😭 that cancel message is supposed to be an ephemeral

deft wolf
# zinc plume yes

Isn't that a bit over complicated? The same thing could be done on the same channel. There is nothing wrong with it, but personally I prefer to do everything on one channel instead of switching, especially since sometimes the bot may fail when creating a channel

sterile lantern
#

you cant send ephemeral messages

#

they must be part of a interaction reply

#

you should do i.reply

#

instead of interaction.channel.send

#

i dont think you can show an ephemeral message to everyone in the game, only to the person who interacted with the button

lament rock
#

this is correct

sterile lantern
#

although discord should support ephemeral msgs outside of interactions cuz they r cool

#

idk why they dont

#

🤷‍♂️

past field
#

ooohhhhhh

sterile lantern
#

in terms of your game (bingo), you could probably just edit the embed

#

stating that the person ended the game

#

you could also disable the buttons which shows that it was canceled

#

basically updating the message with new components, where the buttons are set as disabled

past field
lament rock
#

Create Interaction Response

past field
sterile lantern
#

like that

past field
#

ohhhhhhhh ok i see

#

and everyone who interacted with that button will get that reply

#

that’s what i was trying to get it to do

#

i thought setting it up with ephemeral true would do that lol

#

ok learning moment

past field
sterile lantern
#

i.reply is a response to the interaction

past field
#

ohhhhhhhhh

sterile lantern
#

whereas interaction.channel.send is a regular message sent by the bot in that channel

past field
#

ok i got you

#

i think

sterile lantern
#

youre still not replying to the interaction for the cancel button

past field
#

yeah i just realized

sterile lantern
#

await i.reply({ content: 'You have canceled the game.', ephemeral: true });

#

something like that

past field
sterile lantern
#

what's not working?

past field
#

i’ll screen record, 1 sec

sterile lantern
#

i would probably edit the message at once:

                    // Disable only the cancel button
                    cancelButton.setDisabled(true);
                    row.components = [joinButton, startButton, cancelButton];
                    embed.setDescription("The game has been canceled. Sorry!");
                    await message.edit({ embeds: [embed], components: [row] });

#

just for the sake of efficiency lol

past field
#

oh wait it’s working

#

but i just tried it with about 10 ppl in the lobby and the cancel button failed again 😭

sterile lantern
#

any errors in your logs?

past field
#

oh it works!!!!

#

ok now i need to add a button to give people the option to leave the game before it starts if they want to

karmic delta
oak cliff
#

HMM i cannot help with this

#

I dont work for top.gg anymore, sorry

karmic delta
#

do you know who does? Im not sure who to ping

oak cliff
#

I would escalate it to @harsh nova (leader of the external dev team) and he can escalate it further internally appropriately

sharp geyser
#

but likely not needed depending on what the use case is

#

ones just an encoding library the other is just a date time library that depends on a 3rd party api, both are likely not needed but without looking at where those libs are used its hard to say

karmic delta
#

it is also the 19 junk commits that makes it interesting. It looks botted as the commit names are copies of other commits on the repo
it breaks the library anyways an needs to be fixed

sharp geyser
#

just make a pull request then

harsh nova
#

Yeah this does sound a bit sus. I'll take a look tomorrow but as I'm not that well versed in python it might take a sec or two

karmic delta
#

to clarify the 19 junk commits were just spaces being added and removed

harsh nova
karmic delta
#

it is not normal, also the packages are not needed. I am also curious how they were able to commit directly to main as they have no prior commits or anything

harsh acorn
#

Is there any Discord bots around there that will let me host predictions and then reward the people who picked the winning option. With a leaderboard? I run a eSports server to am wanting to do predictions on games

harsh nova
#

Afaik I don't have admin perms for the repo(s) but I can escalate to the people who do

crude totem
karmic delta
crude totem
sharp geyser
#

That will install the python-sdk prior to all those junk commits

radiant kraken
#

i can make a pr to it

sharp geyser
#

Simple google search

outer crater
#

With BDScript

#

with pyhton

#

python code

@bot.command(name='memberCount')
async def memberCount(ctx):
  await ctx.send(len(bot.users))

BDScript command

$membersCout
#

Why there is huge difference of member count?

deft wolf
#

It probably depends on how each language defines "users". Maybe the Python code shows the number of "unique" users and the BDScript code shows the overall number of users in the cache from each server where if someone is on two servers, it is counted as two

#

I have no experience in either

outer crater
glass pasture
#

here is how you can do it when the user is in multiple guilds, but you want to count them only once

@bot.command(name='mc')
async def mc(ctx):
    unique_members = set()
    for guild in bot.guilds:
        for member in guild.members:
            unique_members.add(member.id)
    await ctx.send(f"{len(unique_members)}")```
outer crater
#

Thanks for the code

#

but bot aint responding to command " mc "

glass pasture
#

worked for me

#

if you are putting it into a cog, don't forget to pass the self

#

And reload it

#

Check if the command is not a duplicate of another async def "mc"

outer crater
#

dumb me using command without perfix

glass pasture
outer crater
#

Thanks!!! it worked

glass pasture
outer crater
#

we need more ppl like you

glass pasture
#

Glad i could help, even so, you gave me an idea to put the number of ppl in the presence LUL

outer crater
#

Thanks again for helping...im kinda dumb, maybe I will be back

glass pasture
#

Well, i have to think to something else

outer crater
#

guys

glass pasture
#

But i will keep that in mind when i reach 5 digit users

pale vessel
glass pasture
#

Actually, yeah
You could do it like this

@bot.command(name='mc')
async def mc(ctx):
    members = len(bot.users)
    await ctx.send(f"{members}")```
#

never cared about members count in guilds YaeHmm

quartz kindle
#

while guild.member_count doesnt

glass pasture
#

i know

#

realised that when i was starting the bot

#

if i was too "fast" it would show me less users

quartz kindle
#

do you fetch all members at start?

glass pasture
quartz kindle
#

thats unmanageable for most slightly larger bots

#

takes way too long to fully start and consumes huge amounts of memory

#

so once you get past a couple thousand guilds, you might wanna turn that off

outer crater
#

hey guys im back

#

how i can get that member count in activity presence

glass pasture
#

*ignore the music, too lazy to pause PRAYGE *

glass pasture
# outer crater how i can get that member count in activity presence

i did it into a cog

from discord.ext import commands, tasks
import discord

class Presence(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.update_presence.start()

    @tasks.loop(minutes=30)
    async def update_presence(self):
        total_users = sum(len(guild.members) for guild in self.bot.guilds)
        await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=f"{total_users} gacha addicts"))

    @update_presence.before_loop
    async def before_update_presence(self):
        await self.bot.wait_until_ready()

def setup(bot):
    bot.add_cog(Presence(bot))```
keep in mind that this method gets the same user for every guild because "bigger number looks better"
deft wolf
#

I guess I'm the only one who doesn't care how many users "use" my bot kappalul

glass pasture
#

It's just... Bigger number make monkey brain go brrrrrr

acoustic bough
#

if you want a big number then track VC time kek

sharp geyser
#

15 thousand days geez

glass pasture
glass pasture
# outer crater

this is how i am loading my cogs
cog_path = 'cogs'
cogs_list = [
'ask',
'askevil',
'avatar_banner',
'banners',
'calculator',
'cute',
'edit',
'feedback',
'gacha_genshin',
'gacha_hi3rd',
'gacha_hsr',
'help',
'manage_gacha',
'music',
'mute',
'nsfw',
'ping',
'presence',
'prison',
'raspunsuri',
'reddit',
'reminders',
'say',
#'topgg',
'usage',
'webhookmanager',
'welcome',
'wiki',
'yande',
'yandesafe',
]

for cog in cogs_list:
bot.load_extension(f'cogs.{cog}')

i am still using a list because sometimes i just want to disable them
you should have

│
├── main.py
│
└── cogs
    │
    └── presence.py
sharp geyser
#

Do you have a cog per command?

glass pasture
#

not always

#

But for some, yeah

sharp geyser
#

That’s an interesting approach

glass pasture
#

it's nice when you can just reload the cog

sharp geyser
#

Typically cogs are made to group commands

glass pasture
#

Well, it depends per use case

#

I find it more suitable like this

#

In my case ask and askevil are kinda the same command but i preffer them to be separate, where
banners - 2 commands
calculator - 2 commands
every gacha has 4 commands etc

sharp geyser
#

Hey whatever works for you

glass pasture
#

yup

earnest phoenix
#

How do I give space in the command name? for example "user info"

deft wolf
#

info is subcommand of user command in this case

#

You can't use spaces in command names

earnest phoenix
sharp geyser
#

Technically you could

#

If it’s message commands

#

But it’s not viable at all

glass pasture
#

That's how you do it in py-cord

#

and for subcommands only

past field
#

question

#

with virtual studio code

#

if i have the terminal open and running my bot on my pc

#

what would happen if i open it and run it on my macbook at the same time?

#

i’m not going to, i’m just curious lol

deft wolf
#

Your bot will most likely start responding twice

past field
#

Ah ok gotcha

deft wolf
#

In the case of slash commands, you will most likely receive an error that this interaction has already received a response

past field
#

thank you!

#

So I was looking into what all is involved with having like server levels and server economy and all that and I read that there needs to be a database connected to the bot. I see that SQLite is a good one… is this information accurate? and if so, is SQLite good to use?

solemn latch
#

I'd recommend using SQLite for now, once you're comfortable, or feel a need to you can move to something better.

past field
solemn latch
#

With sqlite you should be able to handle thousands of servers, possibly up to a few hundred thousand... So I think so ^-^

past field
#

Ok perfect!!! Thank you

#

man

#

yall are teaching me so much

#

So this is another question and I’m sure the answer is loaded af

solemn latch
#

It helps because you're asking good questions, and genuinely want to learn.

past field
#

Is there a way to transfer the data from maki to my database in sqlite?

solemn latch
#

maki? 👀

#

I'm not sure what maki is, do they have a site?

sterile lantern
#

if you host your bot on cf workers, I’m p sure you can’t use sqlite

#

There is mongo http though

#

but yeah if u use slash cmds only cf workers are pretty nice

past field
past field
solemn latch
#

cf workers are amazing, but you dont need to worry about it for now.

sterile lantern
#

lol yeah don’t try using those now

#

they are sooooo painful

#

but something to look at down the road when you have more experience

solemn latch
#

Did you ever get waituntil working?

sterile lantern
#

yep

solemn latch
#

ay

sterile lantern
#

it needed to be a IIFE

solemn latch
#

I'm going to have to look into cf workers again sometime, I'm sure I'll have a use for them again soon.

sterile lantern
#

I think my bot won’t require any updates until discord api v10 is deprecated

solemn latch
solemn latch
#

Will give you another 4 years

#

v6 is still something you can use technically, its up, just not maintained.

#

Right? I forget

acoustic bough
#

is v6 still the default?

solemn latch
#

Last I saw yeah

acoustic bough
solemn latch
#

Yeah it is

#

lmao

sterile lantern
#

I should be fine for a while

past field
#

will i get kicked or anything if I post Maki’s link?

sterile lantern
#

i don’t think so

solemn latch
#

I sure hope not ^-^

#

lol

#

(I asked for it, dont worry)

dawn tendon
#

@solemn latch vote isnt working

solemn latch
#

It'll probably be down for awhile longer 😦

#

Site devs are working on it.

dawn tendon
#

oh

#

did u guys loose sponsers or smtg

solemn latch
#

Not that I'm aware of, I'm not sure why its down, us volunteers havent been told.

dawn tendon
#

oh

#

okay

#

thanks

harsh plover
#

Hey @solemn latch is the site down?

solemn latch
harsh plover
#

Sorry

#

Thanks

#

When did it go down

glass pasture
#

2.5 days ago i think

past field
solemn latch
#

You'd have to probably make a pretty complex piece of code to scrape all the data when someone checks their stats.

Its realistically probably not worth it.

sharp geyser
#

Just listen for messages and read the content of any embeds from maki that matches the stats thing if its an embed

#

then parse that data into json

#

:)

#

Though its really not worth doing

past field
#

dang it

past field
#

ok another question

#

i’m not in any way trying to do this now, i’m just curious

#

but bots that have dash boards on a website… how exactly is that set up????

#

is that a loaded answer?

real rose
#

It all comes down to a database. That is the link between the bot and the dashboard

#

The dashboard is a separate instance to the bot, and the dashboard shows you stuff from your bots database.

past field
#

is that something sqlite can handle as well?

real rose
#

so SQLite is serverless, meaning its not hosted in such a way that it can be remotely connected to. So unless you're hosting the dashboard and bot in the same directory, I'm going to say no.

sharp geyser
#

its a nosql database that has some pretty good libs for it

spark flint
#

why did i sit here reading mongodb as mysql for what felt like 5 minutes

sharp geyser
#

lol

spark flint
#

then reading nosql and thinking tf

sharp geyser
#

lmao

#

Also in case you wonder mo, nosql just means non-relational. It doesn't follow your typical db structure that a sql database like postgres or mysql follows

sharp geyser
past field
#

ah ok ok

past field
sharp geyser
#

Its fine to ignore it for now

#

Mongodb is easier for beginners simply because it doesn't require raw sql queries

#
#

is helpful

eternal osprey
#

hey guys is it actually possible to set guild settings through the bot assuming it has admin perms?

#

like mfalevel, nsflevel, icons, banners, timeouts etc etc

#

this is the full list of settings that i am trying to set by bot.

sharp geyser
#

Technically yes, though I have no idea if bots ignore the 2FA requirement discord puts into place if they are set as onboarding.

sterile lantern
#

the moderator 2fa req?

sharp geyser
#

This applies to anyone with any management perms such as Manage Roles, Channels, Server etc

sterile lantern
#

yeah bots can bypass that

sharp geyser
#

Really anything that affects the server as a whole or users.

#

I figured as much

sterile lantern
#

otherwise they wouldnt be able to ban/kick etc

sharp geyser
#

Though discord is wacky

#

Can't always be sure with discord

sterile lantern
#

discord released a cool mod view

#

on canary at least

#

right click -> mod view

#

super useful

#

i think it was originally acesssible through members tab

#

but now you can just click on a user and view it which saves a lot of time

sharp geyser
#

I wouldn't be surprised if they have the bot owner have to 2FA enabled for banning or kicking to be possible on their bots

sterile lantern
#

lol dont you need 2fa now to create a discord app anyways

sharp geyser
#

idk

sterile lantern
#

it asks me for my 2fa code to reset a token

sharp geyser
#

I never had 2FA turned off

sterile lantern
#

so im assuming they do require it now

sharp geyser
#

That's assuming you don't already have it on

#

ofc it will ask for one if you have it enabled

sterile lantern
#

dont think they'll allow you to perform an action like that w/out 2fa

sharp geyser
#

idk if it will or not if you disable it tho

sterile lantern
#

idk who knows 🤷‍♂️

sharp geyser
#

well you can delete a server just fine without 2fa

#

why would a bot be different

sterile lantern
#

oh really??

sharp geyser
#

ofc

sterile lantern
#

damn

sharp geyser
#

all those who don't have 2fa enabled they can just delete their servers

sterile lantern
#

yeah then you probs dont need 2fa for creating bots then

sharp geyser
#

2FA is just an extra check to make sure you are the one making the request

sharp geyser
#

Yea I figured as much

#

No way would discord make a security loophole like that

sterile lantern
#

it would be funny if they required the bot owner to have nitro for animated bot pfps

sharp geyser
#

I would not be surprised

#

Don't give them any ideas

#

they listen to messages

#

actually idrc

#

I dont make bots anymore

#

do what you will

sterile lantern
#

yeah tbh most bots wont really have a good gif to use anyways

sharp geyser
#

No one is going to be spending the money it requires to get an animated pfp made

#

unless they are a recognized bot

sterile lantern
#

yeah lol

weary warren
#

Does anyone know how to make it to were when u use crime make the fines lower

gilded plankBOT
#

topggDotRed Hey! We think you have our server mistaken. We do not provide support, help, or advice for any bot. You need to click on the "Discord Support Server" button on the bot's page of the bot you need support for. If there isn't a button that says "Discord Support Server" or nothing else mentioned about a support server, the server invite is invalid or you were banned from the bot's support server, then we can't help you. Sorry :(

past field
sharp geyser
#

I code random shit now

#

Whatever comes to mind I just code it

past field
#

like what lol

#

what’s the latest misty masterpiece

sharp geyser
#

apis, applications, even games

past field
#

outside of discord?

sharp geyser
#

yes

past field
#

got any mobile games? 👀

sharp geyser
#

lately I have been more focused on learning C++ and other low level languages though.

#

I am interested in embeded programming

sharp geyser
#

I dont fuck with mobile

past field
#

oh

sharp geyser
#

too much shit to deal with

past field
#

i feel that lol

sharp geyser
#

IOS has their insanely high dev fee

#

and android is just terrible to begin with

sharp geyser
#

and get it signed

#

which is like 100$

#

They also reserve the right to unsign your app

past field
#

android apk’s are unbelievably easy to modify i’m learning

sharp geyser
#

Without warning

#

I'd rather make games and put them on steam or itch.io

#

Even though steam charges the same 100$ fee their support for devs is much better

past field
#

link me to one of your games 👀👀👀👀👀

sharp geyser
#

android is the definition of unsafe

sharp geyser
#

Still WIP

past field
sharp geyser
#

I'm more focused on learning my craft then making something useable rn

past field
#

that’s what i should be doing tbh

#

i’m too eager lol

sharp geyser
#

nothing wrong with it

wheat mesa
#

@sharp geyser you should make a game with my game engine

#

WaffleEngine coming soon (never)™️

sharp geyser
#

I'd love to

past field
sharp geyser
#

yes and no

past field
#

ahh ok

#

that’s what i’m trying to learn more about at the moment

wheat mesa
#

reject node return to C++

#

(and rust)

sharp geyser
#

btw waffle

#

low level learning is very interesting

#

but some of his stuff is still confusing

wheat mesa
#

you'll get used to the fast paced style

sharp geyser
#

mainly when it gets down to him talking about the asm side of things

past field
#

i bet the stuff i say and ask about don’t even make sense half of the time LOL

wheat mesa
sharp geyser
#

I know I just have never looked into it

wheat mesa
#

it's just a matter of "know what this instruction does and what the point of it is"

sharp geyser
#

so its confusing just watching about it

past field
#

man

#

so i got the lobby and buttons and everything for my bingo game functioning properly and perfectly

#

now idk where to start in coding the actual game 😂😂😂

sterile lantern
#

if there’s enough players, run the function startGame() or something

#

you’d have to check based on the amount of ppl in the game which i think u already do

#

so from there you can have a condition to start the game, which can be its own function

#

then in start game you send new buttons and stuff and you go back to the collector and code there

past field
#

ok that’s a good start

#

i was also thinking about the bingo boards

#

planning to use node canvas to generate numbers on a jpg that i’m gonna have in the project folder

sharp geyser
#

@wheat mesa what exactly is a void *

#

I can sort of guess that it is a way of saying you don't know what the type is, but that can also cause issues when referencing stuff from memory no?

wheat mesa
#

void* is just a pointer to any data type

sharp geyser
#

int x = 5;

void *pX = &x; // will error because it doesn't know what type to try and reference
#

at least thats my understanding

wheat mesa
#

void* is C's solution to generics

#

Since C didn't have a concept of generics, it's just a way of representing a bag of some runtime data

sharp geyser
#

I see

wheat mesa
#

For example, malloc returns a void*

sharp geyser
#

I notice most of the memory allocator methods use void pointers

wheat mesa
#

The point of a void pointer is so that you can cast it to whatever you want

sharp geyser
#

I see

#

so

int x = 5;

void *pX = (int)&x; // will error because it doesn't know what type to try and reference
#

I guess there is no reason for it to do so for ints

wheat mesa
#

You know how in your vector implementation you used T*

#

You could replace it with void* and it would be mostly the same

#

(And you would no longer need the <T>)

sharp geyser
#

but say you had a struct

typedef struct {
  char name[64];
  int age;
} Person;

int main() {
  Person *pPerson = (Person*)malloc(sizeof(Person))  

  return 0;
}
wheat mesa
#

Yes

sharp geyser
#

I recall watching something like this in low level learning video

wheat mesa
#

That's very C-like though and usually you refrain from malloc in C++

sharp geyser
#

that casts person to malloc and returns the person struct after its allocated no?

wheat mesa
#

not really

#

malloc just hands you a pointer to a block of memory

sharp geyser
wheat mesa
#

That's why it returns a void*

#

Because you can just cast that void* to whatever you want those bytes to represent

sharp geyser
#

so whats the point of casting to malloc?

wheat mesa
#

huh

#

malloc isn't a type

#

malloc is a function

sharp geyser
#

no no no

#

like casting the return type of malloc

sharp geyser
#

I was wondering why thats a thing

wheat mesa
#

Because then you'd just have a void*

#

And the typechecker wouldn't like that

sharp geyser
#

so basically I am telling the compiler what the type of the data is at that address when I use malloc?