Filter server names with specific permissions (Discord API)

0

I'm using the Discord API to get all the guilds the user is in. With the JSON response, I'm trying to filter out all the server names where the user has the manage_guild permission with list comprehension.

all_guild_names = [x['name'] for x in guilds if int(x['permissions']) & 0x00000020 != 0] guilds is the name of the json response. 'name' and 'permissions' are keys in guilds.

This code doesn't give any errors but it returns an empty list. I want it to return a list of the names of the guilds that has the manage_guild permission. Does anyone know how to do this or how to do it in another way?

Example JSON Response:

user 1 JSON response:
[
 {
 "id": "333",
 "name": "hello"
 "permissions": "0"
 },
 {
 "id": "999",
 "name": "hi"
 "permissions": "1"
 },
 {
 "id": "666",
 "name": "abc"
 "permissions": "2"
 },
]

user 2 JSON response:
[
 {
 "id": "555",
 "name": "hello"
 "permissions": "10"
 },
 {
 "id": "1001",
 "name": "hi"
 "permissions": "6"
 },
 {
 "id": "26236",
 "name": "abc"
 "permissions": "20"
 },
]

The JSON response will be different for each user. That's why I'm using list comprehension to try and search for the value.

python
python-3.x
discord
discord.py
asked on Stack Overflow Apr 12, 2021 by PRA7H1K • edited Apr 15, 2021 by PRA7H1K

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0