-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (25 loc) · 775 Bytes
/
Copy pathutils.py
File metadata and controls
30 lines (25 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
import os
import discord
DATA_FILE = "data.json"
def get_persist():
if not os.path.exists(DATA_FILE):
return {}
with open(DATA_FILE, "r") as f:
try:
return json.load(f)
except json.JSONDecodeError:
return {}
def update_persist(key, value):
data = get_persist()
data[key] = value
with open(DATA_FILE, "w") as f:
json.dump(data, f, indent=4)
async def get_text_channel(bot: discord.Client, channel_id: int):
channel = bot.get_channel(channel_id)
if channel is None:
try:
channel = await bot.fetch_channel(channel_id)
except discord.HTTPException:
return None
return channel if isinstance(channel, discord.abc.Messageable) else None