#permissions overwrites
1 messages Β· Page 1 of 1 (latest)
Why donβt you use edit
Sounds good π―
it's on edit now
can you send actual code?
const { Client, GatewayIntentBits, messageLink, Discord, ConnectionService, IntentsBitField, OverwriteType } = require("discord.js")
// Client Control
const client=new Client({
restRequestTimeout: 120000,
intents:[
GatewayIntentBits.Guilds,//adds server functionality
GatewayIntentBits.GuildMessages, //gets messages from our bot.
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
// SQL Init
var db;
// General Variables and Functions
var TOKEN = '~~~'; // Will .env this at some point
var DEBUG = false;
function getEpoch(){
var DATE = new Date()
return Math.floor(DATE.getTime() / 1000);
}
// Server functions
async function addUserToChannel(member, guild, channelId){
var myChannel = await guild.channels.cache.get(channelId);
await myChannel.permissionOverwrites.edit(member, {
'ViewChannel': true,
'SendMessages': true,
}, OverwriteType.Member);
var perms = await myChannel.permissionOverwrites.cache.get(member.id);
console.log("Added to server: " + member.user.tag + " to " + myChannel.name + " with perms: " + perms);
}
// Client Events
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('guildMemberAdd', async member => {
addUserToChannel(member, member.guild, "1052526652707586068");
});
That should be all the relevant stuff
are you sure #1052526652707586068 is thing?
what do you mean?
I mean 1052526652707586068
yeah, definitely is since it can find it for myChannel
btw I'm sure it will throw error if don't find anything in cache
optional
It just returns undefined if itβs not in the cache
oh wait really
it logs:
Added to server: Tobys578_#9323 to first-landing with perms: 817414141471752308
PermissionOverwrites#edit()
Edits this Permission Overwrite.
member of guildMemberAdd event, last lines
Permission deconstruction for 817414141471752308:
[β] CreateInstantInvite (1) 1<<0
[β] KickMembers (2) 1<<1
[β] BanMembers (4) 1<<2
[β] Administrator (8) 1<<3
[β] ManageChannels (16) 1<<4
[β] ManageGuild (32) 1<<5
[β] AddReactions (64) 1<<6
[β] ViewAuditLog (128) 1<<7
[β] PrioritySpeaker (256) 1<<8
[β] Stream (512) 1<<9
[β] ViewChannel (1024) 1<<10
[β] SendMessages (2048) 1<<11
[β] SendTTSMessages (4096) 1<<12
[β] ManageMessages (8192) 1<<13
[β] EmbedLinks (16384) 1<<14
[β] AttachFiles (32768) 1<<15
[β] ReadMessageHistory (65536) 1<<16
[β] MentionEveryone (131072) 1<<17
[β] UseExternalEmojis (262144) 1<<18
[β] ViewGuildInsights (524288) 1<<19
[β] Connect (1048576) 1<<20
[β] Speak (2097152) 1<<21
[β] MuteMembers (4194304) 1<<22
[β] DeafenMembers (8388608) 1<<23
[β] MoveMembers (16777216) 1<<24
[β] UseVAD (33554432) 1<<25
[β] ChangeNickname (67108864) 1<<26
[β] ManageNicknames (134217728) 1<<27
[β] ManageRoles (268435456) 1<<28
[β] ManageWebhooks (536870912) 1<<29
[β] ManageEmojisAndStickers (1073741824) 1<<30
[β] UseApplicationCommands (2147483648) 1<<31
[β] RequestToSpeak (4294967296) 1<<32
[β] ManageEvents (8589934592) 1<<33
[β] ManageThreads (17179869184) 1<<34
[β] CreatePublicThreads (34359738368) 1<<35
[β] CreatePrivateThreads (68719476736) 1<<36
[β] UseExternalStickers (137438953472) 1<<37
[β] SendMessagesInThreads (274877906944) 1<<38
[β] UseEmbeddedActivities (549755813888) 1<<39
[β] ModerateMembers (1099511627776) 1<<40
Ban members, definitely not what I was expecting π
it looks like role perms
I think they are a bit different
I'm thinking it might be to do with this tbh, should @ everyone be overriding the member's specific perms like that?
nah it shouldn't, everyone aught to be above I would have thought...
Strange that
members are under any role(iirc)
also it will be changed anyway
just with no effect
yeah I thought so, I mean Toby578 doesn't have a role, but I thought the user's specific perms should overwrite everyone
was it even changed? do you see changes in ui?
can't get it to change π
try to do as was said a lot messages ago, change options to object
How do you mean? Sorry js isn't my main language π
join the club XD
{type: <type> }
<Object>: { key: value }
https://discord.js.org/#/docs/discord.js/main/typedef/GuildChannelOverwriteOptions
as you see above it takes object of type and reason
you mean
ViewChannel: true
instead of
'ViewChannel': true ```
?
both are optional
nope, it does same thing
thought so
your last argument in function
await myChannel.permissionOverwrites.edit(member, {
'ViewChannel': true,
'SendMessages': true,
}, OverwriteType.Member);
first is member, second is <Object>: {...} and third is OverwriteType
Didnβt I say that lol
oh yeah, I chucked OverwriteType in and it had no effect
but should be <Object>: {type: <value>}
yeah, I told that it was said a lot messages above
right
Ah
so OverwriteType : { Member: 1 } ? π
definitely not
π
Last argument is { type, reason } object iirc
shall I just remove the last argument? it seems to do nothing for this case...
{type: <OvewriteType>}
its optional but can't be sure why is there type option, it makes sence if it changes something
It's there so cache check is skipped
if not provided, it checks cache and if no role or member is found in cache, it throws an error
Good practice to use that anyways imo
Yeah no change, which I guess with that reason it's not to be expected
d.js has to try to set it internally if you don't (by checking cache and seeing what the snowflake represents)
No chance it would have anything to do with the fact I've joined on the same account before?
tbh I can't see that permissionOverwrites.cache returns collection of bitfields as value.. it seems to return PermissionOverwrites as value
if it is so why does it return 817414141471752308 then
That would be the user the overwrite is for
but why not exactly overwrite?
what?
PermissionOverwriteManager#cache
The cache of this Manager
The overwrite id is the id of the user/role
cache is Collection <Snowflake, PermissionOverwrites>
Yeah, the .id is the user or role id
but myChannel.permissionOverwrites.cache.get(member.id); returns snowflake
hmm, where do they say that?
console.log("Added to server: " + member.user.tag + " to " + myChannel.name + " with perms: " + perms);
Added to server: Tobys578_#9323 to first-landing with perms: 817414141471752308
first message(under reply)
It's not returning a snowflake
They're stringifying it
PermissionOverwrites (extends Base)
Represents a permission overwrite for a role or member in a guild channel.
console.log("Added to server: " + member.user.tag + " to " + myChannel.name + " with perms: " + perms.PermissionOverwrites);
Unhandled promise rejection: TypeError: Cannot read properties of undefined (reading 'PermissionOverwrites')
at addUserToChannel (/bin/DiscordBots/merlin/bot.js:57:105)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
perms is undefined?
Yes
andddd
send actual code
it's randomly started working
randomly started working
sounds like cache issue still
one of the changes must have not saved I guess
if it's really cache issue, it can happen again
async function addUserToChannel(member, guild, channelId){
var myChannel = await guild.channels.cache.get(channelId);
await myChannel.permissionOverwrites.edit(member, {
'ViewChannel': true,
'SendMessages': true,
}, { type: OverwriteType.Member, reason: "Things and Stuff" });
var perms = await myChannel.permissionOverwrites.cache.get(member.id);
console.log("Added to server: " + member.user.tag + " to " + myChannel.name + " with perms: " + perms);
}
// Client Events
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('guildMemberAdd', async member => {
addUserToChannel(member, member.guild, "1052526652707586068");
});
Anyway there's the full code if anyone else is searching the server for it
yeah that is a worry
with { type:<value> } it shouldn't be
maybe that's what fixed it then
all other things as I see always cached/caches when you need it
change just didn't save properly
So you didn't save, it broke
Now you saved, and it works?
worked after I changed it to perms.PermissionOverrides and then back so yeah, must have missed saving it or my server cached it somehow before that

well, cheers for the help π
Object.prototype.valueOf()
The valueOf() method of Object converts the this value to an object. This method is meant to be overridden by derived objects for custom type conversion logic.
Yeah if you go into source and look at Base class (which PermissionOverwrites extends), you'll see valueOf() returns the id
