Skip to content

Commit

Permalink
discord API returning correct number of online users in a server (#1212)
Browse files Browse the repository at this point in the history
* updated discord guild api request

* updated docs

* formatting
  • Loading branch information
froznsm committed Nov 6, 2022
1 parent 41fe8a7 commit 2bae68a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/source/apps/contrib/ads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Command:
Parameters:
None.
Functionality:
Displays the number of users and bots on the server.
Displays the number of users on the server.
Required permission:
None.

Expand Down
14 changes: 3 additions & 11 deletions pyplanet/apps/contrib/ads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ async def chat_discord(self, player, *args, **kwargs):
users = await self.get_discord_users()
if users:
join_url_link = '$l[' + self.discord_join_url + ']Join our Discord$l! '
message = '$ff0$i{}There are currently {} users and {} bots online.' \
.format(join_url_link, users[0], users[1])
message = '$ff0$i{}There are currently {} users online.' \
.format(join_url_link, users)
await self.instance.chat(message, player)

async def get_discord_users(self):
Expand All @@ -214,15 +214,7 @@ async def get_discord_users(self):
try:
async with session.get(url) as response:
data = await response.json()
non_bot_users = []
bots = []
for i in data['members']:
if 'bot' in i:
bots.append(i)
else:
non_bot_users.append(i)
online_users = len(non_bot_users)
return [int(online_users), int(len(bots))]
return int(data['presence_count'])
except Exception as e:
logging.error('Error with retrieving Discord user list')
logging.error(e)
Expand Down

0 comments on commit 2bae68a

Please sign in to comment.