Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.utils import find,get
- from discord.ext import commands
- import asyncio
- import random
- import requests as rq
- import json
- import time
- import events
- img_api = 'f4237223-a9fc-4a7a-b789-e7d2beebcbef' # you can use your own api or use mine
- owm = 'e3d03bf7f7df7af0bbcc77784637a3dd' # you can use your own api or use mine (Open Weather API)
- tc = []
- class Tools:
- def __init__(self,client):
- self.client=client
- @commands.command(pass_context=True)
- async def weather(self,con):
- session = rq.Session()
- """GET THE WEATHER IN YOUR CITY. EX: s.weather austin"""
- city_state = con.message.content[10:]
- t = u"\u00b0"
- try:
- url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid={}'.format(
- city_state, owm)
- ser = session.get(url).text
- rq_json = json.loads(ser)
- temp = rq_json['main']['temp']
- max_temp = rq_json['main']['temp_max']
- min_temp = rq_json['main']['temp_min']
- dis = rq_json['weather'][0]['description']
- wind = rq_json['wind']['speed']
- await self.client.send_message(con.message.channel, "**Temperature** **in** **{}** **is around** {}{}F\n**Minimum Temperature is**: {}{}F\n**Maximum Temperature is**: {}{}F\n**Mainly**: {}\n**Wind speed is around**: {} **MPH**".format(city_state, temp, t, min_temp, t, max_temp, t, dis, wind))
- except:
- await self.client.send_message(con.message.channel, "Looks like something went wrong. Your spelling may be incorrect or the bot may just be able to process this command at the moment.")
- @commands.command(pass_context=True)
- async def userinfo(ctx, member: discord.Member = None):
- roles = [role for role in member.roles]
- embed = discord.Embed(colour=member.colour, timestamp=ctx.message.timestamp)
- embed.set_author(name=member)
- embed.set_thumbnail(url=member.avatar_url)
- embed.add_field(name="ID:", value=member.id)
- embed.add_field(name="Guild name:", value=member.display_name)
- embed.add_field(name="Created at:", value=member.created_at.strftime("%a, %#d %B %Y, %Y, %I:%M %p UTC"))
- embed.add_field(name="Joined at:", value=member.joined_at.strftime("%a, %#d %B %Y, %I:%M %p UTC"), inline=False)
- embed.add_field(name=f"Roles ({len(roles)})", value=" ".join([role.mention for role in roles]))
- embed.add_field(name="Top role:", value=member.top_role.mention)
- await client.send_message(ctx.message.channel,embed=embed)
- @commands.command(pass_context=True)
- async def online(con):
- amt = 0
- for i in con.message.server.members:
- if i.status != discord.Status.offline:
- amt += 1
- await client.send_message(con.message.channel, "**Currently `{}` Members Online In `{}`**".format(amt,con.message.server.name))
- @commands.command(pass_context=True)
- async def offline(con):
- amt = 0
- for i in con.message.server.members:
- if i.status == discord.Status.offline:
- amt += 1
- await client.send_message(con.message.channel, "**Currently `{}` Members Offline In `{}`**".format(amt,con.message.server.name))
- @commands.command(pass_context=True)
- async def iam(con,role:discord.Role):
- """
- Bots can't add roles that has admin permissions to other users"
- THIS MAKES IT SO THAT ANYONE CAN GET ANY ROLE EVEN IF THEIR CURRENT ROLE IS LOWER THAN THE NEW ROLE
- (THIS DOES NOT INCLUDE ADMIN ROLES AS BOT IS NOT ABLE TO ADD IT TO USERS)"""
- try:
- await client.add_roles(con.message.author,role)
- await client.say("Role added")
- except:
- await client.say("Bot could not add that role")
- @commands.command(pass_context=True)
- async def iamnot(con,role:discord.Role):
- """
- Bots can't add roles that has admin permissions to other users"
- THIS MAKES IT SO THAT ANYONE CAN GET ANY ROLE EVEN IF THEIR CURRENT ROLE IS LOWER THAN THE NEW ROLE
- (THIS DOES NOT INCLUDE ADMIN ROLES AS BOT IS NOT ABLE TO ADD IT TO USERS)"""
- try:
- await client.remove_roles(con.message.author,role)
- await client.say("Role removed")
- except:
- await client.say("Bot cannot not remove that role")
- def setup(client):
- client.add_cog(Tools(client))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement