Falexom

Untitled

Jun 4th, 2021 (edited)
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.90 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. import requests
  4. import config
  5. import aiohttp
  6. import asyncio
  7. import json
  8. import random
  9. from bs4 import BeautifulSoup
  10. from random import choice
  11. import youtube_dl
  12. import os
  13.  
  14. from discord.ext import commands
  15.  
  16. bot = commands.Bot(command_prefix='!')
  17.  
  18.  
  19. def clbot(b):
  20.     return b.author == bot.user
  21.  
  22.  
  23. @bot.command(pass_context=True)
  24. async def test(ctx):
  25.     await ctx.send('Yes, it works!')
  26.  
  27.  
  28. @bot.command(pass_context=True)
  29. async def yplay(ctx, url):
  30.     mus = os.path.isfile("music.mp3")
  31.     try:
  32.         if mus:
  33.             os.remove("music.mp3")
  34.     except PermissionError:
  35.         await ctx.send("Already")
  36.     return
  37.     voiceChannel = discord.utils.get(ctx.guild.voice_channels, name=channel)
  38.     await voiceChannel.connect()
  39.     voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
  40.  
  41.     yd_o = {
  42.         'format': 'bestaudio/best',
  43.         'postprocessors': [{
  44.             'key': 'FFmpegExtractAudio',
  45.             'preferredcodec': 'mp3',
  46.             'preferredquality': '192',
  47.         }],
  48.     }
  49.  
  50. @bot.command(pass_context=True)
  51. async def test(ctx):
  52.     await ctx.send('Yes, it works!')
  53.  
  54.  
  55. class FuCo(commands.Cog):
  56.     @bot.command(pass_context=True)
  57.     async def rnum(ctx):
  58.         rc = random.randint(0, 1000000)
  59.         await ctx.send(f"Your random count is:{rc}")
  60.  
  61.     @bot.command(pass_context=True)
  62.     async def rantag(ctx, member: discord.Member):
  63.         guild = bot.get_guild()
  64.         memberList = guild.members
  65.         member = random.choice(memberList)
  66.         await ctx.send(f"{member.mention} mom is gay!!!")
  67.  
  68.     @bot.command(pass_context=True)
  69.     async def rpic(ctx):
  70.         channel = ctx.message.channel
  71.         async with aiohttp.ClientSession() as session:
  72.             async with session.get('https://api.pexels.com/v1/search') as r:
  73.                 embed = discord.Embed(title=f"Your random pic:", color=ctx.guild.me.top_role.color, timestamp=ctx.message.created_at)
  74.                 embed.set_image(url=session.get)
  75.  
  76.  
  77. class Weat(commands.Cog):
  78.     @bot.command(pass_context=True)
  79.     async def weather(ctx, *, city: str):
  80.             api_key = "8d0c5d014b7587a8840240ff79c6e233"
  81.             base_url = "http://api.openweathermap.org/data/2.5/weather?"
  82.             city_name = city
  83.             complete_url = base_url + "appid=" + api_key + "&q=" + city_name
  84.             response = requests.get(complete_url)
  85.             x = response.json()
  86.             channel = ctx.message.channel
  87.             if x["cod"] != "404":
  88.                 async with channel.typing():
  89.                     y = x["main"]
  90.                     current_temperature = y["temp"]
  91.                     current_temperature_celsiuis = str(round(current_temperature - 273.15))
  92.                     current_pressure = y["pressure"]
  93.                     current_humidity = y["humidity"]
  94.                     z = x["weather"]
  95.                     weather_description = z[0]["description"]
  96.                     weather_description = z[0]["description"]
  97.                     embed = discord.Embed(title=f"Weather in {city_name}", color=ctx.guild.me.top_role.color,
  98.                                   timestamp=ctx.message.created_at)
  99.                     embed.add_field(name="Descripition", value=f"**{weather_description}**", inline=False)
  100.                     embed.add_field(name="Temperature(C)", value=f"**{current_temperature_celsiuis}°C**", inline=False)
  101.                     embed.add_field(name="Humidity(%)", value=f"**{current_humidity}%**", inline=False)
  102.                     embed.add_field(name="Atmospheric Pressure(hPa)", value=f"**{current_pressure}hPa**", inline=False)
  103.                     embed.set_thumbnail(url="https://i.ibb.co/CMrsxdX/weather.png")
  104.                     embed.set_footer(text=f"Requested by {ctx.author.name}")
  105.                     await channel.send(embed=embed)
  106.             else:
  107.                 await channel.send("City not found")
  108.  
  109.  
  110. class WALLET(commands.Cog):
  111.  
  112.     @bot.command(pass_context=True)
  113.     async def btc(ctx):
  114.             channel = ctx.channel
  115.             base_url = "https://api.coindesk.com/v1/bpi/currentprice/BTC.json"
  116.             async with channel.typing():
  117.                 async with aiohttp.ClientSession() as session:
  118.                     resp = await session.get(base_url)
  119.                     response = await resp.text()
  120.                     response = json.loads(response)
  121.                     embed = discord.Embed(
  122.                                     title="Bitcoin price is:",
  123.                                     description=f" ${response['bpi']['USD']['rate']}",
  124.                                     color=ctx.guild.me.top_role.color)
  125.                     await channel.send(embed=embed)
  126.  
  127.     @bot.command(pass_context=True)
  128.     async def rub(ctx):
  129.             channel = ctx.channel
  130.             async with channel.typing():
  131.                 DR = 'https://www.google.com/search?sxsrf=ALeKk01NWm6viYijAo3HXYOEQUyDEDtFEw%3A1584716087546&source=hp&ei=N9l0XtDXHs716QTcuaXoAg&q=%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80+%D0%BA+%D1%80%D1%83%D0%B1%D0%BB%D1%8E&oq=%D0%B4%D0%BE%D0%BB%D0%BB%D0%B0%D1%80+&gs_l=psy-ab.3.0.35i39i70i258j0i131l4j0j0i131l4.3044.4178..5294...1.0..0.83.544.7......0....1..gws-wiz.......35i39.5QL6Ev1Kfk4'
  132.                 headers = {
  133.                         'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko)'
  134.                                       ' Chrome/80.0.3987.149 Safari/537.36'}
  135.                 full_page = requests.get(DR, headers=headers)
  136.                 soup = BeautifulSoup(full_page.content, 'html.parser')
  137.                 convert = soup.findAll("span", {"class": "DFlfde", "class": "SwHCTb", "data-precision": 2})
  138.                 embed = discord.Embed(
  139.                             title="USD price is:",
  140.                             description=f" {convert[0].text} ₽ ",
  141.                             color=ctx.guild.me.top_role.color)
  142.                 await channel.send(embed=embed)
  143.  
  144. class Helper(commands.Cog):
  145.     @bot.command(pass_context=True)
  146.     async def helpme(self, ctx):
  147.         channel = ctx.message.channel
  148.         async with channel.typing():
  149.             embed = discord.Embed(title=f"Hi! \nThis is the list of commands:", value=f"****",
  150.                                   color=ctx.guild.me.top_role.color,
  151.                                   timestamp=ctx.message.created_at, )
  152.             embed.add_field(name="!test", value=f"**u can test bot with this command**",  inline=False)
  153.             embed.add_field(name="!clearall", value=f"**removal messages of ALL users, including bot**", inline=False)
  154.             embed.add_field(name="!clearbot", value=f"**remove bot's messages**", inline=False)
  155.             embed.add_field(name="!ban", value=f"**ban member**", inline=False)
  156.             embed.add_field(name="!weather + <city>",  value=f"**show weather in the city**", inline=False)
  157.             embed.add_field(name="!random", value=f"**random count**", inline=False)
  158.             embed.set_footer(text=f"Requested by {ctx.author.name}")
  159.             await channel.send(embed=embed)
  160.  
  161.  
  162. class Comandi(commands.Cog):
  163.     @bot.command(pass_context=True)
  164.     async def test(ctx):
  165.         channel = ctx.channel
  166.         async with channel.typing():
  167.             await ctx.send('Все работает')
  168.  
  169.     @bot.command(pass_context=True)
  170.     async def clearbot(ctx):
  171.         channel = ctx.channel
  172.         delete = await channel.purge(limit=10000, check=clbot)
  173.  
  174.     @bot.command(pass_context=True)
  175.     async def clearall(ctx):
  176.         channel = ctx.channel
  177.         remove = await channel.purge(limit=100000)
  178.         channel = ctx.channel
  179.         async with channel.typing():
  180.             await ctx.send('Deleted {} messages'.format(len(remove)))
  181.  
  182.     @bot.command(pass_context=True)
  183.     async def ban(ctx, member : discord.Member, *, reason=None):
  184.         await member.ban(reason=reason)
  185.         channel = ctx.channel
  186.         async with channel.typing():
  187.             await ctx.send('User banned')
  188.  
  189.  
  190. class Inf:
  191.     @bot.command(pass_context=True)
  192.     async def my_top_role(ctx):
  193.         roles = ctx.author.roles
  194.         roles.reverse()
  195.         top_role = roles[0]
  196.         channel = ctx.channel
  197.         async with channel.typing():
  198.             await ctx.send(top_role)
  199.  
  200.     @bot.command(pass_context=True)
  201.     async def top_role(ctx, member: discord.Member):
  202.         roles = member.roles
  203.         roles.reverse()
  204.         top_role = roles[0]
  205.         channel = ctx.channel
  206.         async with channel.typing():
  207.             await ctx.send(top_role)
  208.  
  209.     '''
  210.    @bot.command(pass_context=True)
  211.    async def info(ctx, member: discord.Member):
  212.        channel = ctx.channel
  213.        roles = member.roles
  214.        low_role = roles[0]
  215.        roles.reverse()
  216.        top_role = roles[0]
  217.        ava = member.avatar_url
  218.        async with channel.typing():
  219.            embed = discord.Embed(title=f"Member information", value=f"****",
  220.                                            color=ctx.guild.me.top_role.color,
  221.                                            timestamp=ctx.message.created_at, )
  222.            embed.add_field(name="Nickname", value=f"**{member}", inline=False)
  223.            embed.add_field(name="Role(s)", value=f"**The top role is: {top_role},"
  224.                            f" the lowest role is: {low_role}**", inline=False)
  225.            embed.set_thumbnail(url=ava)
  226. '''
  227.  
  228.  
  229. class Eve:
  230.     @bot.event
  231.     async def on_member_remove(ctx,  member: discord.Member, reason=None):
  232.         await member.ban(reason=reason)
  233.         await ctx.send("This user has already left the guild and now banned")
  234.  
  235.     @bot.event
  236.     async def on_member_join(member):
  237.         if welcome_channel := member.guild.get_channel(754741279918410952):
  238.             await welcome_channel.send(f"Hi {member.mention}!")
  239.  
  240. bot.run(config.TOKEN)
  241.  
  242. # полный бот, больше к нему не возвращаюсь, мораль думайте сами
Add Comment
Please, Sign In to add comment