#Foxxxy's stupid brain hurts lol

1 messages ยท Page 1 of 1 (latest)

ripe loom
#

yo

#

@hard torrent am in here ๐Ÿ˜„

hard torrent
#

okay first we need the actual command, fetch the command first, it's a ban command, right?
guild.commands.fetch()
fetches them all
then resolve the promise, it gives you the collection of all the commands
then find by it's name, which i assume is "ban"

left acornBOT
ripe loom
#

ok but in what file do I do such thing lmfao

hard torrent
#

it's a uhh one time thing right? you can do this once on your ready event and just remove it afterwards

ripe loom
#

uhhhhh

#

I believe so yeah joyful

hard torrent
#

you have a ready event listener, just put it there for now, but be sure to remove it, we dont' wanna send needless api requests over and over

#

alternatively there is the using the raw api with @discordjs/rest but i think it'd be a bit more complicated to follow

ripe loom
#

yeah I'll just go for the first option lmao ๐Ÿ˜‚

#

right, I am in the onReady command now - what to do, what to do think

hard torrent
#

fetch the command first, then log it and make sure it is the one you want
even though it probably will be

ripe loom
#

alr

#

wait what

#

your guilds thing dont work @hard torrent

hard torrent
#

this is why we test, what doesn't work
be more specific

#

you didn't just slap on the guild.commands.fetch, did you?

ripe loom
#

oh no sir-e-do

#

hold on

hard torrent
#

you're supposed to get a guild by using client.guilds.cache.get("the guild id where the command is registered")

ripe loom
#

yeah one sec

#

yeah that worked

#

got the command aight

#

works great

#

ok now what you_think_about_that

hard torrent
#

no, you need the command from discord,
you need an ApplicationCommand instance
not to be confused by your own created Command class

#

fetch the command the way i told you
<Guild>.commands.fetch(), resolve promise, then find

ripe loom
#

OHH ALRIGHT

#

its all clicking now

#

one sec lol

#

alr so it is a Promise { <pending> }

#

So what now?

#

Or did I fuck everything up again lol

hard torrent
#

resolve the promise, await

ripe loom
#

SHIT LMAO forgot, so sorry

#

ok cool

#

didnt print anything ๐Ÿ’€

#

OH THERE WE GO

hard torrent
#

add a .catch(console.error)

ripe loom
#

FUCKING HELL THATS A LOT

#

OH

#

Just shit like this ๐Ÿคฃ

#

yeah its working alright ๐Ÿ’€

#

alr what now?

hard torrent
#

first, you'd make the permission overwrites

#

so let's get some context, you know the everyone role is the same as the guild id?

ripe loom
#

did not fucking know that

#

but aight

#

yeah

hard torrent
#

like this server, this guild
it's id is 222078108977594368
and <@&222078108977594368> is <@&222078108977594368>
the id matches
so treat the guild id as the everyone role id

ripe loom
#

alr

hard torrent
ripe loom
#

do I not do it like that? thinkLul

hard torrent
#

ApplicationCommand.options does not exist

ripe loom
#

damn

hard torrent
#

or at least not how you think it does

ripe loom
#

yeah can see that....

hard torrent
#

and the .get("suspend-user") is probably invalid, it's a javascript Map, Maps have keys and values right?

the key for this map is the Command ID, not the name

#

so get wouldn't work, use find,
the thing is it's not really just a map, it's a Collection, an extended map with array methods like find

ripe loom
#

ok

#

why is this so hard may I ask to just set a command to only be able to be disabled by set people?

#

its like what

#

oh shit

#

I think I might?! have done it?! idk man

hard torrent
#

done what
for now just try to log the application command

ripe loom
#

alright got the application command to print

#

all good

#

how would I do the disabling part good sir?

hard torrent
#

let me do a test first

ripe loom
#

oh? alright.

hard torrent
#

okay thank god, it works

#

phew
well okay so the plan is as usual

we'll enable the command for you,
we'll disable the command for the @everyone role

ripe loom
#

uhuh.....

#

go on

hard torrent
ripe loom
#

what of applicationcommand?

#

can see it all here, using TS

hard torrent
#

command is the ApplicationCommand

ripe loom
#

yeah

#

IK that much

hard torrent
#

first,
enable the command for you

id is your id 930744788859359282
type is "USER"
permission will be true, because we want to enable it

#

don't do anything, just put this in an object and show me what you made

ripe loom
#

like that?

#

oh wait

hard torrent
#

type is role

ripe loom
#

USER on the second one should change to role yeah

#

got it

hard torrent
#

for the everyone role

ripe loom
#

got it

hard torrent
#

๐Ÿ‘
now the method i mentioned, <ApplicationCommand>.permissions.add

ripe loom
#

TypeScript is having a stroke?

#

is something up or

#

OH I NEED TO ADD IT IN AN OBJECT

#

oh thats dumb

hard torrent
#

not really, try passing that as an object
{permissions: permissions} or the shorthand {permissions}

ripe loom
#

yeah

#

thats dumb as fuck

#

but aight

hard torrent
#

this is the same method used in the manager, soooo there's that

ripe loom
#

ts moment

#

that right there is a certified typescript moment

hard torrent
#

just don't use a variable then, pass it directly

ripe loom
#

dies

#

But- wwwhy?!

#

Why is it a problem?!

hard torrent
#

maybe as const will fix it

ripe loom
#

wdym as const

hard torrent
#

const permissions = [....] as const

#

basically it thinks this object's type's type is string and not "ROLE" | "USER"

ripe loom
#

still fucking dies

hard torrent
#
let myStr = "str" // type is string
let myStr = "str" as const // type is the "str" string literal```
ripe loom
#

literally just adding the type def fixed it

#

๐Ÿ’€

#

whelp ok

#

alr lemme try this!

hard torrent
#

that works too of course

ripe loom
#

ye ๐Ÿ˜ƒ

hard torrent
#

buut i wasn't sure of the type and the docs aren't loading :(

ripe loom
#

cool it fucking works

#

lets go

#

is there a way to basically add this onto the command, not in the ready function?

hard torrent
#

like on your command handler? yeaaaaaaah it gets far too complicated see
you can't really add permissions to a command on create, you can't just edit a command and edit it's permisison, for some reason discord and their infinite wisdom decided to make it super trashy and you need to do these separately

ripe loom
#

like huh

#

๐Ÿ‘€

#

then he sets it

#

like the fuck

hard torrent
#

by using bad practices, i'll never in my life recommend a recon video

ripe loom
#

why the hell is that?!

hard torrent
#

or a wokcommand or a codelyon video, because they are the shits

ripe loom
#

he made some good stuff to learn from, which is kinda where i started...

ripe loom
#

Havent heard of codelyon yet though...

hard torrent
#

well let's not get derailed, i never said it's not possible, the thing is it is
it's complicated and super limited but we can incorporate it with the registering function

ripe loom
#

Cant I just like, add a custom thingy on to my command object - then check for that in the register function, and that object inside the main object has the permissions stuff?

#

like in here before the run function?

hard torrent
#

do you want to set up the system now?

#

is this bot open sourced?

ripe loom
#

Not OS, made a bad decision in accidentally having the token in one or two of the commits - so uh

#

I can make a new repo

hard torrent
#

nah it's not really needed, i just wanted to see your command handler structure

#

correct me if i'm wrong, in every file there is a new Command, right?

ripe loom
#

oh I can just send you screenshots if you like

hard torrent
#

okay that's all i need for now
so add a little property to the Command class, name it permissions or something

ripe loom
#

yeah will do one second ๐Ÿ˜ƒ

#

one second, I am gonna post the code somewhere so you can just flick through it mate

hard torrent
#

alrighty then

ripe loom
#

Shouldn't be any creds in that so I should be fine, but I trust you and have systems in place just in case lol

#

Can you open it or is it private @hard torrent

hard torrent
#

i can
so okay you need to modify your CommandType

ripe loom
#

alrighty

#

in the file now

hard torrent
ripe loom
#

uh

#

wait

#

oh right

#

yeah

#

done matey

hard torrent
#

hey uhh where's your deploy-commands.ts or like whatever you use?

ripe loom
#

oh made it optional too

hard torrent
#

please tell me it's there

ripe loom
hard torrent
#

๐Ÿ˜ญ

ripe loom
#

It's fine - it really is not an issue.

#

Let's focus on the thing at hand if that's ok ๐Ÿ˜ƒ

hard torrent
#

this is exactly why i don't recommend videos from weird channels
like
okay here's why it's wrong, this is sending an api request EVERY time your bot turns on, and at times it's not even doing anything, but it's sending the request and eating up your rate limit quota

ripe loom
#

there is a quota?!??!?!?

hard torrent
#

you know there's a rate limit, right?

ripe loom
#

yeah?

hard torrent
#

yeah keep sending requests over and over and you get rate limited

ripe loom
#

oh dude it's only 50 requests per second limit its cool

#

right

#

***back to the thing at hand haha yes dies ***

hard torrent
#

no, this is the most wrong misconception people have, it's not just that, that is just there saying if you send 50 requests per second you will definitely get rate limited
every api request may have a different rate limit, it's different per bot, per endpoint

ripe loom
#

alright well I will definitely fix this then like tommorrow or something

#

back to the permissions thing pls?

hard torrent
#

:(

ripe loom
#

LMAO

#

its cool dude

#

right

#

ok

#

so I have modified the interface, what now?

hard torrent
#

are all your commands going to be operating on a single specific server?

ripe loom
#

yeah

#

bot is single-guild

hard torrent
#

okay so the interface is fine
let's go to your cursed command registering part

ripe loom
#

๐Ÿ˜ƒ

#

aha yes

#

(will be fixed soonโ„ข๏ธยฎ)

hard torrent
#

over here
first off, await this this.application?.commands.set(commands);
we'll need to wait for the commands to be registered before we modify the permissions

ripe loom
#

Alright

hard torrent
#

now, set the result as a variable

ripe loom
#

Awaited

hard torrent
#

the set returns a promise and it resolves to a Collection of all the commands you have

ripe loom
#

on line 37 of Client.ts?

hard torrent
#

yea

ripe loom
#

alright

hard torrent
#

const registeredCommands = await ...

ripe loom
#

got it mate

hard torrent
#

also since it's a single guild bot why not register it on the guild?

ripe loom
#

Will be adding multi guild support (possibly) in the future

#

So wanna just keep it there, for now.

hard torrent
#

do permissions work on global commands?

ripe loom
#

yeah

#

wait

#

I fucking hope so

#

hold on ill check

hard torrent
#

well i know it works on guild commands

ripe loom
#

yeah it does

#

it exists on that type

#

so yeah - 99% sure it works fine.

#

right so what now then :D

hard torrent
#

no, no it doesn't

ripe loom
#

wut

hard torrent
#

well they only work on guild specific commands

ripe loom
#

damn

#

ok

hard torrent
#

okay moving on
register on the guild, await it, set it to a variable

ripe loom
#

what would you do if it was a multi guild bot then?!?!??!

hard torrent
#

variable

ripe loom
#

oh right

hard torrent
#

and make the guild a variable too, we'll reuse that

ripe loom
#

I uh-

#

where ๐Ÿ˜ƒ

hard torrent
#

the this.guilds.cache.get("ID")

ripe loom
#

oh make that one a var too?

hard torrent
#

yea

ripe loom
#

alr

#

one sec

#

done that

#

what's next kind sir joyy

hard torrent
#

why are you using var?

ripe loom
#

you said make a variable?!??!

#

I thought you meant var not const facepalm

hard torrent
#

const or let is used to make variables

ripe loom
#

sorry dude

#

yeah

#

I know

#

misinterpretation issue on my end, sorry brother

#

cool

#

now what Thonk

hard torrent
#

also

const guild = this.guilds.cache.get("ID")

guild.commands.set
```this is what i meant
#

split it up, set the guild to a variable

ripe loom
#

ohkay

#

So like this? getting a tad confused now ๐Ÿ˜‚

hard torrent
#

no, split up that line
this.guilds.cache.get("ID") .commands.set(...)

const guild = this.guilds.cache.get("ID")

guild.commands.set
ripe loom
#

alright finally done it

#

now hwat

hard torrent
#

look at the example here

ripe loom
#

OH so just like in the onReady thing

hard torrent
#

yes except this time it's dynamic

ripe loom
#

oh?

#

wait what example - the all or one command one

hard torrent
#

the second one

ripe loom
#

alr

#

wait wouldnt that then set it to all commands?!?!??!?!

hard torrent
#

it will

#

okay so you store stuff on this.commands, right?

ripe loom
#

yuh

hard torrent
#

so we're going to have to work with two sets of datas

ripe loom
#

alright

#

yeah thats the commands thingy :D

hard torrent
#

okay that's wrong
first off, the guilds.cache.get
name that as guild, remove await

#

await the set, and make that the guildRegisteredCommands variable

#

look at these two lines

#

the first one is a guild, not the registered commands
the second line would be (promise) the commands

ripe loom
#

and done

#

๐Ÿ˜„

hard torrent
#

so now we'll work with two sets up datas
guildRegisteredCommands and client.commands/this.commands

ripe loom
#

alrighty

#

thats A-OK

hard torrent
#

we need this.commands for the permission data, and we need the id from the registeredCommands

ripe loom
#

ok

#

cool

hard torrent
#

so, first off, what is the thing both of these have in common and is unique? they both have names
so that's the bridge between the two

ripe loom
#

alr

hard torrent
#

https://discord.js.org/#/docs/discord.js/stable/class/ApplicationCommandPermissionsManager?scrollTo=set look at the structure again
it's similar to the one we used already
except it's like this

{id: "commandID", permissions: [permissionDataWeUsedEarlier]}
ripe loom
#

alright cool

#

and whats the ID for?

#

like guild ID?

hard torrent
#

we can go at it both ways but call map on guildRegisteredCommands

you want to get the return an object with it's id first, we'll work with the permission later

ripe loom
#

or I am so confused lol

#

ahh yeah was gonna do that

#

alright

hard torrent
ripe loom
#

dat one

#

OH THAT WOULD BE THE COMMAND ID

#

right?

#

alr so what do you want me to put in the map then?

hard torrent
#

return an object

ripe loom
#

wdym

hard torrent
#

in the map, the callback, return an object with the id

ripe loom
#

I uh

hard torrent
#
commands.map(cmd => {
  return {id: cmd.id}
})
ripe loom
#

oh right ok

#

alright got it

#

now what do I do with that map shit

hard torrent
#

yes now we need to add permissions

#

so we talked about the bridge, we talked about how the name is the same, right?

ripe loom
#

yeah

hard torrent
#

inside the callback, create a variable named i guess storedCommand?
and find a command on this.commands where the command name matches the command.name

#

this.commands.find((cmd) => cmd.name === command.name)

ripe loom
#

did that

hard torrent
#

and this storedCommand has a permissions, right?

#

show me your CommandType again

ripe loom
#

the custom type has it yeah

#

commandPermissions

#

is what I named it

#

so yeah

#

all good

hard torrent
#

commandPermissions, the type should be an array

ripe loom
#

uh

#

no it doesnt

#

oh wait your right lol

#

yeah sorry

#

alright cool

#

now what

hard torrent
#

so on the object you return the id, return permissions: storedCommand.permissions

ripe loom
#

dude what the fuck

#

where would one put this

#

I am so sorry, I am getting quite lost

hard torrent
ripe loom
#

yeah?

#

what about it

#

also return permissions aswell?

hard torrent
#

add a permissions property to it, and that'll be the value

ripe loom
#

right alright ok

#

alr

#

done like this

hard torrent
#

yea

ripe loom
#

ok - whats the final steps as I need to feed my kids lmao

hard torrent
#

the map, store this to a variable
name it fullPermissions

ripe loom
#

so sorry I sound rude lol

hard torrent
#

no i'm feeding you the code too, it's alright

ripe loom
#

LMAOOO

#

damn

#

done thatttt

hard torrent
#

the second one, you can just pass {fullPermissions} and you're done

ripe loom
#

that no likey

#

ts is having a bit of a moment again

#

big stack trace ๐Ÿ˜ณ

#

I mean

#

It should be working, right?

#

says this at the bottom if it helps btw

hard torrent
#

try casting that as an array of GuildApplicationCommandPermissionData

ripe loom
#

No such type/interface exists

hard torrent
#

guess djs just doesn't export it then?

ripe loom
#

was gonna cast it by doing the type then the shit in ()

#

but like still

ripe loom
#

this is a certified ts moment

#

ill push the code rn to GH if you wanna check what I have done - one sec

#

done

#

16 secs ago

hard torrent
#

can you hover over fullPermissions?

ripe loom
#

of type any dude

hard torrent
#

oh shit

#

uhh type the variable as so

const fullPermissions: {id: string, permissions: ApplicationCommandPermissionData[]}[] = ...
```that should be it
#

oh wait yeah edited

#

i wonder why djs doesn't export the type tho

ripe loom
#

Alright lemme try it in a sec

#

Brb

#

that uh

#

@hard torrent

#

does not work

#

smh why is ts being a stupid

hard torrent
#

permissionResolvable???

#

OOOOOOOOOOOHHHHHH you dummy, you used .userPermissions and not commandPermissions

#

aaah my brain

ripe loom
#

OH FOR FUCK SAKE LMAOOOO

#

nice one - did not realise that -_-

#

ok yeah now it works without the typing

#

alr cool

#

so is that it then? will it work now?!

hard torrent
#

yes, now typescript should help you whenever you want to add permissions to the commands
and the permisisons will be on the command class

ripe loom
#

yeah I know

#

can see

#

v cool

#

alr lets try it with another command :D

hard torrent
#

well time for me to go watch adventure time with my baby sister, need me if you ping me, ciao ๐Ÿคจ

ripe loom
#

Thanks a lot, think it works - but yeah: super duper appreciate the help man

#

Big up to you <3

#

Have a nice time then :D

hard torrent
#

she's the worst
and remember to move to what the guide recommends
we can convert it later on another thread if you want but that's super duper important

ripe loom
#

also RIP her lmao

#

alright cya later mate, thanks again :)

#

OH FOR FUCK SAKE @hard torrent

#

turns out the code did a STUPID and doesn't work, I know you left so imma just leave this here lol

hard torrent
#

log it too

ripe loom
#

alr

#

thats the fullPermissions arr

#

Object, Object?! Da fuq?

hard torrent
#

undefined?

#

oh right? ah right right it makes sense

ripe loom
#

undefined means the command doesnt have any perms

#

lmao

#

means I didn't specify it

#

but thats not the issue

hard torrent
#

filter it
by this

ripe loom
#

wdym

hard torrent
#

fuck no

ripe loom
#

huh?!

hard torrent
#

filter them by all where the permission is undefined
that'll work

ripe loom
#

fuck no?

hard torrent
#

permissions is optional right? we forgot to deal wtih that

ripe loom
#

yeah...

#

but is that NOT the issue?!?!??!?!?

hard torrent
#

that is, it being undefined is

ripe loom
#

oh so it being undefined is the issue, right ok

#

I guess I can filter all the shit to make it so that it is only the non-undefined ones ig

#

ok that tiny line on line 52 might have worked (the bottom one in the photo)

#

yeah no error

#

wait it may have worked?!

hard torrent
#

probably

ripe loom
#

Cool

#

it fucking works now flawlessly, thanks so much dude