Skip to content

Commit

Permalink
Update use of discord.py for version 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ephphatha authored and AJenbo committed Apr 20, 2024
1 parent f66f3a7 commit 1247429
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions discord_bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
from collections import deque
import datetime
import discord
import json
import logging
Expand Down Expand Up @@ -31,7 +30,7 @@ def escape_discord_formatting_characters(text: str) -> str:

def format_game_message(game: Dict[str, Any]) -> str:
ended = time.time() - game['last_seen'] >= config['game_ttl']
text = '';
text = ''
if ended:
text += '~~' + game['id'].upper() + '~~'
else:
Expand Down Expand Up @@ -168,7 +167,7 @@ def any_player_name_contains_a_banned_word(players: List[str]) -> bool:
async def update_message(message: discord.Message, text: str) -> Optional[discord.Message]:
if message.content != text:
try:
await message.edit(content=text)
message = await message.edit(content=text)
except discord.errors.NotFound:
return None
return message
Expand Down Expand Up @@ -237,6 +236,7 @@ async def background_task() -> None:
if message_index < len(active_messages):
message = await update_message(active_messages[message_index], message_text)
assert message is not None
active_messages[message_index] = message
else:
message = await send_message(message_text)
assert message is not None
Expand All @@ -250,11 +250,11 @@ async def background_task() -> None:
active_messages.append(message)
else:
await update_message(active_messages[game_count], format_status_message(game_count))

activity = discord.Activity(name='Games online: '+str(game_count), type=discord.ActivityType.watching)
await client.change_presence(activity=activity)
except discord.errors.DiscordServerError as server_error:
logger.warn(repr(server_error))
except discord.DiscordException as discord_error:
logger.warn(repr(discord_error))


@client.event
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
discord>=2.*

0 comments on commit 1247429

Please sign in to comment.