Created
August 30, 2018 09:20
-
-
Save TheRockettek/155a9d6bf7de70be62d351305fde84fa to your computer and use it in GitHub Desktop.
A Discord.py (rewrite) example for a discord bans lookup incl. mutliple cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import discord | |
import asyncio | |
import json | |
client = discord.Client() | |
async def check(userid): | |
headers = {'Authorization': 'Your-Token-Here'} | |
url = "https://bans.discord.id/api/check.php?user_id=" + userid | |
async with aiohttp.ClientSession() as session: | |
resp = await session.get(url, headers = headers) | |
final = await resp.text() | |
resp.close() | |
data = json.loads(final) | |
result = [] | |
for s in data: | |
if s["banned"] == "0": | |
result.append(["0"]) | |
elif s["banned"] == "1": | |
result.append(["1", s["case_id"], s["reason"], s["proof"]]) | |
return result | |
@client.event | |
async def on_message(msg): | |
if msg.author.bot: | |
return | |
if msg.content.startswith("=banned ") or msg.content.startswith("=check "): | |
await msg.delete() | |
edi = await msg.channel.send(content = "Looking up <a:plswait:480058164453179428>") | |
userid = "" | |
if msg.content.startswith("=banned "): | |
userid = str(int(msg.content.replace("=banned ", ""))) | |
elif msg.content.startswith("=check "): | |
userid = str(int(msg.content.replace("=check ", ""))) | |
usar = await client.get_user_info(int(userid)) | |
res = await check(userid) | |
clr = 0x42f49b # green | |
mkay = "https://i.imgur.com/dgMFwTq.png" | |
beaned = 0 | |
blacklisted = "No, this user is safe" | |
if "1" in [s[0] for s in res]: | |
clr = 0xfc6262 | |
beaned = 1 | |
blacklisted = "Yes, this user is global banned" | |
mkay = "https://i.imgur.com/ExscAMH.png" | |
eme = discord.Embed(color = clr, title = "Discord Bans Lookup") | |
eme.set_author(name = usar.name + "#" + usar.discriminator, icon_url = mkay, url = "https://bans.discord.id") | |
eme.set_footer(text = "Requested by " + msg.author.name + "#" + msg.author.discriminator) | |
eme.timestamp = msg.created_at | |
eme.set_thumbnail(url = usar.avatar_url) | |
eme.add_field(name = "User ID", value = userid, inline = True) | |
eme.add_field(name = "User", value = usar.name + "#" + usar.discriminator, inline = True) | |
if ".gif" in usar.avatar_url: # is_animated is not working well | |
eme.add_field(name = "Avatar", value = "[Click](" + usar.avatar_url + ")", inline = True) | |
else: | |
eme.add_field(name = "Avatar", value = "[Click](" + usar.avatar_url_as(format = "png", size = 1024) + ")", inline = True) | |
eme.add_field(name = "Blacklisted", value = blacklisted, inline = True) | |
if beaned == 1: | |
eme.add_field(name = "Cases", value = "\n".join(["ID: " + str(s[1]) + "\nReason: " + s[2] + "\nProof: [Click](" + s[3] + ")\n" for s in res] ) , inline = False) | |
await edi.edit(embed = eme, content = "") | |
client.run("potato") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment