async def ping(self, ctx): embed = discord.Embed(timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description='Pinging...') embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) t = await ctx.send(embed=embed) ms = t.created_at - datetime.datetime.utcnow() embed1 = discord.Embed(timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description=f'Pong! `{str(ms)[-2:]}`ms') embed1.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) await t.edit(embed=embed1)
async def invite(ctx): """Just if you want to invite me""" embed = discord.Embed( color=EmbedUtils.random_color(), description= "Invite **[Assistant](https://discordapp.com/oauth2/authorize?client_id=507971831945494528&permissions=8&scope=bot)** to your server!" ) await ctx.send(embed=embed)
async def dadjoke(self, ctx): async with aiohttp.ClientSession() as cs: async with cs.get("https://icanhazdadjoke.com", headers={"Accept": "application/json"}) as r: res = await r.json() embed = discord.Embed(timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color()) embed.add_field(name="Dad Joke \U0001f935", value=f'```fix\n{res["joke"]}```') embed.set_footer(text=f'Requested by {ctx.author}', icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def botclear(self, ctx, amount: int = None): owners = [409258904053350400, 240855733208481792] if amount is None: amount = 100 if not ctx.author.guild_permissions.manage_messages and not ctx.author.id in owners: await ctx.send("Hold on!\nYou require `manage messages` permissions to execute this command!🚫") return if ctx.author.id in owners or ctx.author.guild_permissions.manage_messages: try: mgs = await ctx.channel.purge(limit=amount, check=lambda msg: msg.author.bot) embed = discord.Embed(timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description=f"✅ Succesfully deleted `{len(mgs)}` message(s)!") embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) msg = await ctx.send(embed=embed) await msg.delete() await ctx.message.delete() except discord.errors.Forbidden: embed = discord.Embed(timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description="🚫 I require `manage messages` permissions to execute this command!") embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def learn(ctx, *, name: str): with open("memory.json", "r+") as f: data = json.load(f) if name in data['learned']: embed = discord.Embed( timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color, description="I have learned that already, mate.") embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) else: embed = discord.Embed( timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description= f"The name of that, what I have learned is \"{name}\". What about the content?" ) embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) msg = await bot.wait_for('message', check=lambda msg: msg.author == ctx.author and msg.channel == ctx.channel) embed = discord.Embed( timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description= f"The name of that, what I have learned is \"{name}\". The content is {msg.content}, should I leave it by that or do you want to cancel it?" ) embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_footer(text="Answer with yes/no | 30 seconds left.", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) def check(msg): return msg.content == "yes" try: await bot.wait_for('message', check=check, timeout=30) except TimeoutError: embed = discord.Embed( timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description= "You did not enter a valid option after 30 seconds so the command has been aborted." ) embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_footer(text="This command has been aborted.", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) try: if str(ctx.guild.id) in data['learned']: data['learned'].update({msg.content: name}) else: data['learned'][ctx.guild.id].update({msg.content: name}) except KeyError: data['learned'][ctx.guild.id] = {} data['learned'][ctx.guild.id].update({msg.content: name}) f.seek(0) json.dump(data, f) f.truncate() f.close() embed = discord.Embed( timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description="Thanks for teaching me some cool stuff!") embed.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) embed.set_footer( text=f"{bot.user.name} has learned something new!", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def uploademoji(self, ctx, url: str, name: str): response = aiohttp.ClientSession().get(url).read() emoji = await ctx.guild.create_custom_emoji(image=response, name=name) embed = discord.Embed(timestamp=datetime.datetime.utcnow(), color=EmbedUtils.random_color(), description=f"**{ctx.author}**, I have uploaded the emoji {str(emoji)} to this server!") embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed)
async def eval(self, ctx, *, body: str): """Evaluates a code""" owners = [240855733208481792, 409258904053350400] if not ctx.author.id in owners: return env = { "bot": self.bot, "ctx": ctx, "channel": ctx.channel, "author": ctx.author, "guild": ctx.guild, "message": ctx.message, "self": self, "_": self._last_result } def cleanup_code(content): if content.startswith('```') and content.endswith('```'): return '\n'.join(content.split('\n')[1:-1]) env.update(globals()) body = cleanup_code(body) stdout = io.StringIO() to_compile = f'async def func():\n{textwrap.indent(body, " ")}' try: exec(to_compile, env) except Exception as e: return await ctx.send(f'```py\n{e.__class__.__name__}: {e}\n```') func = env['func'] try: with redirect_stdout(stdout): ret = await func() except Exception as e: value = stdout.getvalue() return await ctx.send( f'```py\n{value}{str(traceback.format_exc()).replace("Arash", "User")}\n```' ) else: value = stdout.getvalue() try: await ctx.message.add_reaction('\u2705') except: pass if ret is None: if value: try: embed = discord.Embed( color=EmbedUtils.random_color(), description= f":inbox_tray: **Input**\n{ctx.message.content.replace(';eval', '')}\n:outbox_tray: **Output**\n```markdown\n{value}\n```" ) embed.set_footer( text="Evaluated in " + str(self.bot.latency)[:-13] + " milliseconds", icon_url= "https://images-ext-1.discordapp.net/external/3ySfWfvhv6j0ycZwm6fYA7jcOfrzST69owF2zCYu30I/https/www.python.org/static/opengraph-icon-200x200.png" ) await ctx.send(embed=embed) except discord.errors.HTTPException: with open("error.txt", "w+") as f: f.write(value) await ctx.send(file=discord.File("error.txt")) else: _last_result = ret try: embed = discord.Embed( color=EmbedUtils.random_color(), description= f":inbox_tray: **Input**\n{ctx.message.content.replace(';eval', '')}\n:outbox_tray: **Output**\n```markdown\n{value}{ret}\n```" ) embed.set_footer( text="Evaluated in " + str(self.bot.latency)[:-13] + " milliseconds", icon_url= "https://images-ext-1.discordapp.net/external/3ySfWfvhv6j0ycZwm6fYA7jcOfrzST69owF2zCYu30I/https/www.python.org/static/opengraph-icon-200x200.png" ) await ctx.send(embed=embed) except discord.errors.HTTPException: with open("error.txt", "w+") as f: f.write(f"{value}{ret}") await ctx.send(file=discord.File("error.txt"))