Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. import discord
  2. from discord.utils import find,get
  3. from discord.ext import commands
  4. import asyncio
  5. import random
  6. import requests as rq
  7. import json
  8. import time
  9. import events
  10.  
  11. img_api = 'f4237223-a9fc-4a7a-b789-e7d2beebcbef' # you can use your own api or use mine
  12. owm = 'e3d03bf7f7df7af0bbcc77784637a3dd' # you can use your own api or use mine (Open Weather API)
  13. tc = []
  14.  
  15. class Tools:
  16. def __init__(self,client):
  17. self.client=client
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. @commands.command(pass_context=True)
  26. async def weather(self,con):
  27. session = rq.Session()
  28. """GET THE WEATHER IN YOUR CITY. EX: s.weather austin"""
  29. city_state = con.message.content[10:]
  30. t = u"\u00b0"
  31. try:
  32. url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid={}'.format(
  33. city_state, owm)
  34. ser = session.get(url).text
  35. rq_json = json.loads(ser)
  36. temp = rq_json['main']['temp']
  37. max_temp = rq_json['main']['temp_max']
  38. min_temp = rq_json['main']['temp_min']
  39. dis = rq_json['weather'][0]['description']
  40. wind = rq_json['wind']['speed']
  41. 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))
  42. except:
  43. 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.")
  44.  
  45.  
  46.  
  47. @commands.command(pass_context=True)
  48. async def userinfo(ctx, member: discord.Member = None):
  49. roles = [role for role in member.roles]
  50. embed = discord.Embed(colour=member.colour, timestamp=ctx.message.timestamp)
  51. embed.set_author(name=member)
  52. embed.set_thumbnail(url=member.avatar_url)
  53. embed.add_field(name="ID:", value=member.id)
  54. embed.add_field(name="Guild name:", value=member.display_name)
  55. embed.add_field(name="Created at:", value=member.created_at.strftime("%a, %#d %B %Y, %Y, %I:%M %p UTC"))
  56. embed.add_field(name="Joined at:", value=member.joined_at.strftime("%a, %#d %B %Y, %I:%M %p UTC"), inline=False)
  57. embed.add_field(name=f"Roles ({len(roles)})", value=" ".join([role.mention for role in roles]))
  58. embed.add_field(name="Top role:", value=member.top_role.mention)
  59. await client.send_message(ctx.message.channel,embed=embed)
  60.  
  61.  
  62. @commands.command(pass_context=True)
  63. async def online(con):
  64. amt = 0
  65. for i in con.message.server.members:
  66. if i.status != discord.Status.offline:
  67. amt += 1
  68. await client.send_message(con.message.channel, "**Currently `{}` Members Online In `{}`**".format(amt,con.message.server.name))
  69.  
  70.  
  71.  
  72. @commands.command(pass_context=True)
  73. async def offline(con):
  74. amt = 0
  75. for i in con.message.server.members:
  76. if i.status == discord.Status.offline:
  77. amt += 1
  78. await client.send_message(con.message.channel, "**Currently `{}` Members Offline In `{}`**".format(amt,con.message.server.name))
  79.  
  80.  
  81.  
  82. @commands.command(pass_context=True)
  83. async def iam(con,role:discord.Role):
  84. """
  85. Bots can't add roles that has admin permissions to other users"
  86. THIS MAKES IT SO THAT ANYONE CAN GET ANY ROLE EVEN IF THEIR CURRENT ROLE IS LOWER THAN THE NEW ROLE
  87. (THIS DOES NOT INCLUDE ADMIN ROLES AS BOT IS NOT ABLE TO ADD IT TO USERS)"""
  88. try:
  89. await client.add_roles(con.message.author,role)
  90. await client.say("Role added")
  91. except:
  92. await client.say("Bot could not add that role")
  93.  
  94.  
  95.  
  96. @commands.command(pass_context=True)
  97. async def iamnot(con,role:discord.Role):
  98. """
  99. Bots can't add roles that has admin permissions to other users"
  100. THIS MAKES IT SO THAT ANYONE CAN GET ANY ROLE EVEN IF THEIR CURRENT ROLE IS LOWER THAN THE NEW ROLE
  101. (THIS DOES NOT INCLUDE ADMIN ROLES AS BOT IS NOT ABLE TO ADD IT TO USERS)"""
  102. try:
  103. await client.remove_roles(con.message.author,role)
  104. await client.say("Role removed")
  105. except:
  106. await client.say("Bot cannot not remove that role")
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. def setup(client):
  116. client.add_cog(Tools(client))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement