fetching format from jsonfile thats in github
This commit is contained in:
parent
6b5a3eaf28
commit
80217fcc4e
13
welcomeCog/info.json
Normal file
13
welcomeCog/info.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"author": [
|
||||
"Deathblade"
|
||||
],
|
||||
"install_msg": "May Kanuim show you the way",
|
||||
"name": "Welcome",
|
||||
"short": "Sends a welcome dm thats written in a specific format to the users",
|
||||
"description": "Sends a welcome dm thats written in a specific format to the users",
|
||||
"requirements": ["requests"],
|
||||
"tags": [
|
||||
"welcome"
|
||||
]
|
||||
}
|
||||
@ -1,36 +1,37 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import json
|
||||
import requests
|
||||
|
||||
def fetchMessage():
|
||||
with open('embedded_message.json') as file:
|
||||
try:
|
||||
jsonFormat = json.load(file)
|
||||
print(int(jsonFormat["color"],16))
|
||||
message=discord.Embed(title=str(jsonFormat["title"]), description="".join(map(str, jsonFormat["description"])), color=int(jsonFormat["color"],16))
|
||||
message.set_thumbnail(url=jsonFormat["thumbnail"])
|
||||
for field in jsonFormat["fields"]:
|
||||
if(field["id"]!="links"):
|
||||
message.add_field(name=field["name"], value=field["value"], inline=field["inline"])
|
||||
else:
|
||||
message.add_field(name=field["name"], value="".join(map(str,field["value"])), inline=field["inline"])
|
||||
embed = requests.get("https://raw.githubusercontent.com/Kanium/KanuimCogs/master/welcomeCog/embedded_message.json").text
|
||||
|
||||
message.set_footer(text=jsonFormat["footer"]["text"], icon_url=jsonFormat["footer"]["icon_url"])
|
||||
return message
|
||||
def fetchMessage(jsonFormat):
|
||||
try:
|
||||
message=discord.Embed(title=str(jsonFormat['title']), description=''.join(map(str, jsonFormat['description'])), color=hex(jsonFormat['color']))
|
||||
message.set_thumbnail(url=jsonFormat['thumbnail'])
|
||||
for field in jsonFormat['fields']:
|
||||
if(field['id']!='links'):
|
||||
message.add_field(name=field['name'], value=field['value'], inline=field['inline'])
|
||||
else:
|
||||
message.add_field(name=field['name'], value=''.join(map(str,field['value'])), inline=field['inline'])
|
||||
|
||||
except:
|
||||
return "Welcome To Kanuim !"
|
||||
message.set_footer(text=jsonFormat['footer']['text'], icon_url=jsonFormat['footer']['icon_url'])
|
||||
return message
|
||||
|
||||
except:
|
||||
return 'Welcome To Kanuim !'
|
||||
|
||||
class WelcomeCog(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.message = fetchMessage()
|
||||
self.message = json.load(embed)
|
||||
self.bot = bot
|
||||
|
||||
@commands.Cog.listener()
|
||||
@commands.guild_only()
|
||||
async def on_member_join(self, member: discord.Member):
|
||||
try:
|
||||
await member.send(content=None, embed=self.message)
|
||||
message = fetchMessage(self.message)
|
||||
await member.send(content=None, embed=message)
|
||||
except:
|
||||
print(
|
||||
f'Error Occured! sending a dm to {member.display_name} didnt work !')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user