I need help applying functions to my discord bot.

Here is the code block for the function of confirm:
if (confirmation.customId === 'confirm') {

await confirmation.update({
embeds: [{
title: 'Lockdown confirmed!',
description: `The lockdown will commence in 5 seconds.`,
color: '15548997',
}],
ephemeral: true,
components: [],
},);

}
if (confirmation.customId === 'confirm') {

await confirmation.update({
embeds: [{
title: 'Lockdown confirmed!',
description: `The lockdown will commence in 5 seconds.`,
color: '15548997',
}],
ephemeral: true,
components: [],
},);

}
i need a way to remove the sendmessage permissions of the role 1171206894799552622 of certain channels, if someone could write the code it'd be great, the id's are below. 1174066163941126215, 1174066275618664560, 1174066357797658764, 1174066422637408396
59 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
NyR
NyR9mo ago
#rules 3 we won't write codes for but we can guide you
paxton!!
paxton!!OP9mo ago
okay if someone could guide me thatd be great im profficient in js but not this library
d.js docs
d.js docs9mo ago
:method: PermissionOverwriteManager#edit() Edits permission overwrites for a user or role in this channel, or creates an entry if not already present.
paxton!!
paxton!!OP9mo ago
how do i define the channal channel* or is this the channel the message was sent it in*
NyR
NyR9mo ago
Do you want to edit the channel where interaction took place or some other channel?
paxton!!
paxton!!OP9mo ago
i want to edit the channels: 1174066163941126215, 1174066275618664560, 1174066357797658764, 1174066422637408396 denying sendmessages for the role 1171206894799552622 if you could guide me thatd be great also, ive tried attaching the code to the top of the if statement, but for some reason, the catch statement instantly initializes instead of waiting for timeout thats why i was wondering if you could tell me how to properly insert the code
NyR
NyR9mo ago
You can put the channels id in an array and use for...of loop to iterate over it, and inside the loop get the channel with const channel = <Client>.channels.cache.get('id') then call channel.permissionsOverwrites.edit() inside the loop
paxton!!
paxton!!OP9mo ago
what do i put for <client>
NyR
NyR9mo ago
It's your bot's instance, almost all structures from discordjs has that property, so if you have interaction , you can access it via interaction.client
paxton!!
paxton!!OP9mo ago
alright i will do that to be clear const channel = interaction.client.channels.cache.get('1214631357209387089'); channel.permissionsOverwrites.edit({ SendMessages: false } ) but where do i define the id for the role being editted
NyR
NyR9mo ago
The first parameter in overwrite must be userid or role id then overwrites options
paxton!!
paxton!!OP9mo ago
so roleId: 123445667, then put the change
NyR
NyR9mo ago
It's explained here if you go to the link
paxton!!
paxton!!OP9mo ago
i see i scrolled a little bit more and saw
const channel = interaction.client.channels.cache.get('1214631357209387089');
channel.permissionsOverwrites.edit({
id: 1171206894799552622,
deny: [PermissionsFlagsBit.ViewChannel],
}
)
const channel = interaction.client.channels.cache.get('1214631357209387089');
channel.permissionsOverwrites.edit({
id: 1171206894799552622,
deny: [PermissionsFlagsBit.ViewChannel],
}
)
so like this it does that weird instant catch thing again idk how to explain instead of running that code, it runs the catch statement at the bottom i can send the entire file if youd like
paxton!!
paxton!!OP9mo ago
Mar 5, 2024, 6:46 PM
paxton.rip
i <3 carti
NyR
NyR9mo ago
No...! The link to the doc has a code snippet on how to provide options
paxton!!
paxton!!OP9mo ago
no i do look i use button builder but im not sure how to run functions for the button can you tell me how to do that
NyR
NyR9mo ago
But this is the wrong way
paxton!!
paxton!!OP9mo ago
this is my entire file without any functions
paxton!!
paxton!!OP9mo ago
bru
NyR
NyR9mo ago
<Channel>.permissionOverwrites.edit('userid', {
ViewChannels: False
})
<Channel>.permissionOverwrites.edit('userid', {
ViewChannels: False
})
paxton!!
paxton!!OP9mo ago
oh! thats mb its sending me to catch because of error what if i want to edit a role id instead of a user
NyR
NyR9mo ago
What is the error ? Please show the full stack
paxton!!
paxton!!OP9mo ago
no error in console
NyR
NyR9mo ago
Provide role id instead of userid
paxton!!
paxton!!OP9mo ago
okay i will try once again sending me to the catch statement i will send you the entire js file no console output tho
paxton!!
paxton!!OP9mo ago
Mar 5, 2024, 6:50 PM
paxton.rip
i <3 carti
NyR
NyR9mo ago
Because you do not log errors in your catch block, please log it and show the errors
paxton!!
paxton!!OP9mo ago
console.log(e);
d.js docs
d.js docs9mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
NyR
NyR9mo ago
And please use one of these to share codes, as it's easier to read Yeah
paxton!!
paxton!!OP9mo ago
TypeError: Cannot read properties of undefined (reading 'edit') at Object.execute (C:\Users\Paxton Warin\Repositories\Abyss-Bot\commands\moderation\lockdown.js:43:55) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Client.<anonymous> (C:\Users\Paxton Warin\Repositories\Abyss-Bot\index.js:37:3) cant read the edit property i define channel properly: const channel = interaction.client.channels.cache.get('1214631357209387089'); and i think i change the permissions correctly: channel.permissionsOverwrites.edit('1171206894799552622', { ViewChannels: False })
NyR
NyR9mo ago
Show full code, how you define channels how you get it, etc and please use one of these to share
paxton!!
paxton!!OP9mo ago
ill js send you the entire js file
NyR
NyR9mo ago
Not file
paxton!!
paxton!!OP9mo ago
what do you want oh ill send you the try catch and everything in there that will show you pastebin work?
NyR
NyR9mo ago
I want you to show me the full code
paxton!!
paxton!!OP9mo ago
like the repo? i dont understand
NyR
NyR9mo ago
Just the file concerning the error not full repo
paxton!!
paxton!!OP9mo ago
??? so you want me to send you the command file right?
paxton!!
paxton!!OP9mo ago
Pastebin
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandB...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
NyR
NyR9mo ago
I thought you were sending the file as an attachment, mb
paxton!!
paxton!!OP9mo ago
oh
NyR
NyR9mo ago
Can you log channel please and see what it returns
paxton!!
paxton!!OP9mo ago
ye
NyR
NyR9mo ago
Wait...
paxton!!
paxton!!OP9mo ago
Pastebin
TextChannel { type: 0, guild: Guild { id: '11711936 - Pasteb...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
NyR
NyR9mo ago
It's permissionOverwrites not permissionsOverwrites
paxton!!
paxton!!OP9mo ago
bru ok we got somewhere but now its saying false is not defined
paxton!!
paxton!!OP9mo ago
Mar 5, 2024, 7:01 PM
paxton.rip
i <3 carti
paxton!!
paxton!!OP9mo ago
once again i am not familiar with this library so idk what it requires for its params
NyR
NyR9mo ago
false lowercase, and it's basic js, not related to djs
paxton!!
paxton!!OP9mo ago
oh didnt notice that it was taking it as a different form ye okay so it needs a bitfield instead of viewchannels i would paste the error but its long
NyR
NyR9mo ago
Also change to ViewChannel i mis-remembered, an oversight on my part No (s) at the end
paxton!!
paxton!!OP9mo ago
yo thank you it worked
NyR
NyR9mo ago
Np...
paxton!!
paxton!!OP9mo ago
have a great day
Want results from more Discord servers?
Add your server