Page MenuHomeAITSYS Dev
Authored By
aiko
Thu, Oct 7, 22:17
Size
4 KB
Subscribers
None
import io
import urllib
import urllib.request
from datetime import datetime
import discord
from PIL import Image
from discord.ext import commands
class CommandClass(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def hello_world(self, ctx):
await ctx.send("Hello World!")
@commands.command()
async def test_my_world(self, ctx, role: discord.Role) -> None:
"""
Sends the Icon of the Role
:param ctx:
Discord Command Context
:param role:
The Discord Role
:return:
None
"""
await ctx.send(role.icon)
@commands.command()
async def give_my_url(self, ctx, role: discord.Role) -> None:
"""
Sends the Url of the Role
:param ctx:
Discord Command Context
:param role:
The Discord Role
:return:
None
"""
await ctx.send(role.icon.url)
@commands.command()
async def test_my_unicode(self, ctx, role: discord.Role) -> None:
"""
Sends the Unicode emote (throws an error if there is no unicode emote as icon)
:param ctx:
Discord Command Context
:param role:
The Discord Role
:return:
None
"""
whaat = role.unicode_emoji
await ctx.send(whaat)
@commands.command()
async def test_my_pic(self, ctx, role: discord.Role):
"""
Sets the Role Icon to NONE
:param ctx:
Discord Command Context
:param role:
The Discord Role
:return:
None
"""
#
try:
await role.edit(icon=None)
except Exception as e:
await ctx.send(e)
await ctx.send("Done")
@commands.command()
async def save_this(self, ctx, role: discord.Role) -> None:
"""
Saved the Icon Image as File (same what .save() does)
:param ctx:
Discord Command Context
:param role:
The Discord Role
:return:
None
"""
url = role.icon.url
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
headers = {'User-Agent': user_agent, }
request = urllib.request.Request(url, headers=headers)
response = urllib.request.urlopen(request)
data = response.read()
image = Image.open(io.BytesIO(data))
image.save("somethere.png")
await ctx.send("ok")
@commands.command()
async def sets_my_image(self, ctx, role: discord.Role) -> None:
"""
Sets the Image as Role icon
:param ctx:
Discord Command Context
:param role:
Discord Role
:return:
None
"""
with open("img.png", "rb") as image:
f = image.read()
# b = bytearray(f)
await role.edit(icon=f)
await ctx.send("just trying")
@commands.command()
async def emote_lol(self, ctx, role: discord.Role) -> None:
"""
Sets the Role Icon to Unicode Emote
:param ctx:
Discord Command Context
:param role:
Discord Role
:return:
None
"""
await role.edit(unicode_emoji='❌')
await ctx.send("what u gonna do?")
@commands.command()
async def av_lol(self, ctx, member: discord.Member, role: discord.Role) -> None:
"""
Sets the tagged Member Icon as Role Icon
:param ctx:
Discord Command Context
:param member:
Discord Member
:param role:
Discord Role
:return:
None
"""
avatar = await member.display_avatar.with_size(32).read()
await role.edit(icon=avatar)
await ctx.send("Stop making me weird stuff")
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
"""
Error handler
:param ctx:
:param error:
:return:
"""
self.counter = + 1
embed = discord.Embed(title="Ops, there is an error!",
description="Error report Nr. {} after reset.".format(self.counter),
color=ctx.author.color)
embed.add_field(name='Server:', value='{}'.format(ctx.message.guild), inline=True)
embed.add_field(name='Command:', value='{}'.format(ctx.message.content), inline=False)
embed.add_field(name='Error:', value="```python\n{}```".format(error), inline=False)
embed.set_thumbnail(url=self.bot.user.display_avatar)
embed.set_footer(text='Error Message')
embed.timestamp = datetime.utcnow()
await ctx.channel.send(embed=embed)
print(error)
def setup(bot):
bot.add_cog(CommandClass(bot))

File Metadata

Mime Type
text/x-python
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
3464
Default Alt Text
cmd.py (4 KB)

Event Timeline

aiko changed the visibility from "All Users" to "Public (No Login Required)".Thu, Oct 7, 22:18