Update welcome.py

This commit is contained in:
Fadi AT 2020-03-30 19:40:47 +03:00
parent a3f8c74e33
commit 88e1efa0d6

View File

@ -8,19 +8,13 @@ from redbot.core.utils.chat_formatting import box, humanize_list, pagify
url = 'https://raw.githubusercontent.com/Kanium/KanuimCogs/master/welcomeCog/data/embedded_message.json'
def fetchMessage():
async def fetch(session, url):
async def fetchMessage():
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.text()
async def call():
async with aiohttp.ClientSession() as session:
html = await fetch(session, url)
html = await response.text()
x = json.loads(str(html))
return x
return call()
def formatMessage(jsonFormat):
try:
message=discord.Embed(title=str(jsonFormat['title']), description=''.join(map(str, jsonFormat['description'])), color=hex(jsonFormat['color']))
@ -42,11 +36,13 @@ def formatMessage(jsonFormat):
class WelcomeCog(commands.Cog):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.message = fetchMessage()
self.message = ''
@commands.Cog.listener()
async def on_member_join(self, member: discord.Member):
try:
if self.message == '':
self.message = await fetchMessage()
message = formatMessage(self.message)
await member.send(content=None, embed=message)
except (discord.NotFound, discord.Forbidden):