arikawa
arikawa copied to clipboard
v3: Inconsistent channel permission values for large guilds between sessions
Every other session ends up with channels in a specific large guild not having permissions (returning 0). The three other smaller guilds the account is in do not have this issue.
I have triaged with another one of my bot accounts in that guild running Dysnomia, targeting that account to check permissions across all channels and it shows correct values.
Additional context: ningen is used
How are you getting channel permissions? What's your code?
for _, channel := range guildChannels {
if channel.Type != discord.GuildText && channel.Type != discord.GuildAnnouncement {
continue
}
private := false
if channel.ParentID.IsValid() {
category, err := client.ChannelStore.Channel(channel.ParentID)
if err == nil {
perms := discord.CalcOverwrites(*guild, *category, *selfMember)
private = !perms.Has(discord.PermissionViewChannel)
}
}
if private {
perms := discord.CalcOverwrites(*guild, channel, *selfMember)
private = !perms.Has(discord.PermissionViewChannel)
}
if private && !withPrivate {
continue
}
// ...
}
CalcOverwrites will not try to fetch missing permissions from the given channel. You must use client.Permissions to fetch that. Ideally, CalcOverwrites should not even be used at all.
client.Permissions is consistently returning 0 now when it should be returning 401295005309505 for most of the channels.
What does client.Client.Permissions return? (Make sure that client.Client is specifically of type *api.Client.)
*api.Client does not seem to have a Permissions function
Sorry, try client.Client.Channel and check its permissions. Also note that these functions don't handle carrying over category permissions.
The permission results seems to be inverted with using !channel.SelfPermissions.Has(discord.PermissionViewChannel), where it thinks the private channels are the ones that the account can see. This is also way too slow for my liking.
I did make my own version of client.Permissions to debug with, and the root cause seems to be guild.Roles being empty.
Hmm, so https://github.com/diamondburned/arikawa/blob/v3.3.3/state/state.go#L310 should probably error out when Roles == nil then, which makes sense. (Not the function itself, but this particular branch.)