#Foxxxy's stupid brain hurts lol
1 messages ยท Page 1 of 1 (latest)
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"
ApplicationCommand#name
The name of this command
yeah its like a suspend command for my custom matchmaking bot
ok but in what file do I do such thing lmfao
it's a uhh one time thing right? you can do this once on your ready event and just remove it afterwards
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
yeah I'll just go for the first option lmao ๐
right, I am in the onReady command now - what to do, what to do 
fetch the command first, then log it and make sure it is the one you want
even though it probably will be
this is why we test, what doesn't work
be more specific
you didn't just slap on the guild.commands.fetch, did you?
you're supposed to get a guild by using client.guilds.cache.get("the guild id where the command is registered")
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
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
resolve the promise, await
add a .catch(console.error)
FUCKING HELL THATS A LOT
OH
Just shit like this ๐คฃ
yeah its working alright ๐
alr what now?
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?
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
alr
the thing i made you get right now, is a ApplicationCommand
and we'll be using the <ApplicationCommand>.permissions.add method https://discord.js.org/#/docs/discord.js/stable/class/ApplicationCommandPermissionsManager?scrollTo=add
it takes an array of permission objects https://discord.js.org/#/docs/discord.js/stable/typedef/ApplicationCommandPermissionData
check this object out first
do I not do it like that? 
ApplicationCommand.options does not exist
damn
or at least not how you think it does
yeah can see that....
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
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
done what
for now just try to log the application command
alright got the application command to print
all good
how would I do the disabling part good sir?
let me do a test first
oh? alright.
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
so did you check the object structure here?
command is the ApplicationCommand
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
type is role
for the everyone role
got it

TypeScript is having a stroke?
is something up or
OH I NEED TO ADD IT IN AN OBJECT
oh thats dumb
not really, try passing that as an object
{permissions: permissions} or the shorthand {permissions}
this is the same method used in the manager, soooo there's that
just don't use a variable then, pass it directly
maybe as const will fix it
wdym as const
const permissions = [....] as const
basically it thinks this object's type's type is string and not "ROLE" | "USER"
still fucking dies
r-right ok
let myStr = "str" // type is string
let myStr = "str" as const // type is the "str" string literal```
that works too of course
ye ๐
buut i wasn't sure of the type and the docs aren't loading :(
cool it fucking works
lets go
is there a way to basically add this onto the command, not in the ready function?
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
then how the fuck did this recon dude do it? https://www.youtube.com/watch?v=OX_YpAgkJBE
Don't know what this is?
Watch the discord.js handler video to set things up: https://www.youtube.com/watch?v=8yLIPTxrj08
Need help? Feel free to join the discord server ๐
Links:
Discord (recon dev): https://discord.io/reconlx
Github: https://github.com/reconlx
...
like huh
๐
then he sets it
like the fuck
by using bad practices, i'll never in my life recommend a recon video
why the hell is that?!
or a wokcommand or a codelyon video, because they are the shits
he made some good stuff to learn from, which is kinda where i started...
WOKCommands is dogshit I can confirm
Havent heard of codelyon yet though...
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
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?
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
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?
oh I can just send you screenshots if you like
๐
affirmative
okay that's all i need for now
so add a little property to the Command class, name it permissions or something
yeah will do one second ๐
one second, I am gonna post the code somewhere so you can just flick through it mate
alrighty then
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
i can
so okay you need to modify your CommandType
you see the type you used there? CommandType.permissions would have this type ApplicationCommandPermissionData[]
hey uhh where's your deploy-commands.ts or like whatever you use?
oh made it optional too
please tell me it's there
It is inbuilt inside of the Client class.
๐ญ
lmao
It's fine - it really is not an issue.
Let's focus on the thing at hand if that's ok ๐
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
there is a quota?!??!?!?
you know there's a rate limit, right?
yeah?
yeah keep sending requests over and over and you get rate limited
oh dude it's only 50 requests per second limit its cool
right
***back to the thing at hand haha yes
***
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
alright well I will definitely fix this then like tommorrow or something
back to the permissions thing pls?
:(
here's the guide for registering which you'll follow "tomorrow".. whenever that will be, hopefully that is tomorrow
https://discordjs.guide/interactions/slash-commands.html#registering-slash-commands
but that's significantly different than the approach i need to improvise now
are all your commands going to be operating on a single specific server?
okay so the interface is fine
let's go to your cursed command registering part
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
Alright
now, set the result as a variable
Awaited
the set returns a promise and it resolves to a Collection of all the commands you have
wdym, so make it:
await this.application?.commands.set(commands);
on line 37 of Client.ts?
yea
alright
const registeredCommands = await ...
got it mate
also since it's a single guild bot why not register it on the guild?
Will be adding multi guild support (possibly) in the future
So wanna just keep it there, for now.
do permissions work on global commands?
well i know it works on guild commands
yeah it does
it exists on that type
so yeah - 99% sure it works fine.
right so what now then :D
no, no it doesn't
well they only work on guild specific commands
okay moving on
register on the guild, await it, set it to a variable
what would you do if it was a multi guild bot then?!?!??!
done that :D
variable
oh right
and make the guild a variable too, we'll reuse that
the this.guilds.cache.get("ID")
oh make that one a var too?
yea
why are you using var?
const or let is used to make variables
sorry dude
yeah
I know
misinterpretation issue on my end, sorry brother
alr
cool
now what 
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
no, split up that line
this.guilds.cache.get("ID") .commands.set(...)
const guild = this.guilds.cache.get("ID")
guild.commands.set
now the method we'll be using is guild.permissions.set https://discord.js.org/#/docs/discord.js/stable/class/ApplicationCommandPermissionsManager?scrollTo=set
look at the example here
OH so just like in the onReady thing
yes except this time it's dynamic
the second one
yuh
so we're going to have to work with two sets of datas
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
so now we'll work with two sets up datas
guildRegisteredCommands and client.commands/this.commands
we need this.commands for the permission data, and we need the id from the registeredCommands
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
alr
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]}
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
which one? the one that says commandID?
dat one
OH THAT WOULD BE THE COMMAND ID
right?
alr so what do you want me to put in the map then?
return an object
wdym
in the map, the callback, return an object with the id
commands.map(cmd => {
return {id: cmd.id}
})
yes now we need to add permissions
so we talked about the bridge, we talked about how the name is the same, right?
yeah
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)
did that
the custom type has it yeah
commandPermissions
is what I named it
so yeah
all good
commandPermissions, the type should be an array
so on the object you return the id, return permissions: storedCommand.permissions
the returnied object
add a permissions property to it, and that'll be the value
yea
ok - whats the final steps as I need to feed my kids lmao
the map, store this to a variable
name it fullPermissions
so sorry I sound rude lol
alright got it
no i'm feeding you the code too, it's alright
https://discord.js.org/#/docs/discord.js/stable/class/ApplicationCommandPermissionsManager?scrollTo=set check the example again
the second one, you can just pass {fullPermissions} and you're done
that no likey
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
try casting that as an array of GuildApplicationCommandPermissionData
No such type/interface exists
guess djs just doesn't export it then?
yeah...
this is a certified
moment
ill push the code rn to GH if you wanna check what I have done - one sec
done
16 secs ago
can you hover over fullPermissions?
of type any dude
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
Alright lemme try it in a sec
Brb
that uh
@hard torrent
does not work
smh why is
being a stupid
permissionResolvable???
OOOOOOOOOOOHHHHHH you dummy, you used .userPermissions and not commandPermissions
aaah my brain
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?!
yes, now typescript should help you whenever you want to add permissions to the commands
and the permisisons will be on the command class
well time for me to go watch adventure time with my baby sister, need me if you ping me, ciao ๐คจ
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
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
alright got it
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
log it too
undefined means the command doesnt have any perms
lmao
means I didn't specify it
but thats not the issue
filter it
by this
wdym
fuck no
huh?!
filter them by all where the permission is undefined
that'll work
permissions is optional right? we forgot to deal wtih that
that is, it being undefined is
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?!
probably


moment



