[text] Code

Viewer

  1. import discord
  2. import os
  3. from discord import app_commands
  4. from discord.ext import commands
  5. import yt_dlp
  6.  
  7. Id = os.environ['Id']
  8. my_secret = os.environ['TOKEN']
  9.  
  10. bot = discord.Client(intents=discord.Intents.default())
  11. tree = app_commands.CommandTree(bot)
  12. Guild = discord.Object(id=Id)
  13.  
  14. @bot.event
  15. async def on_ready():
  16.   await tree.sync(guild=discord.Object(id=Id))
  17.   channel = bot.get_channel(1086317826228367461)
  18.   await channel.send("connected")
  19.   print("Ready!")
  20.  
  21.  
  22. @tree.command(name="hello", description="Greet me", guild=Guild)
  23. async def hello(contex, url: str):
  24.     print("downloading")
  25.     # Muestra una rueda de carga mientras se descarga la música
  26.     loading_message = await contex.response.send_message('Cargando...')
  27.  
  28.     # Descarga la música utilizando yt-dlp
  29.     ydl_opts = {
  30.         'format': 'bestaudio/best',
  31.         'outtmpl': 'song',
  32.         'postprocessors': [{
  33.             'key': 'FFmpegExtractAudio',
  34.             'preferredcodec': 'mp3',
  35.             'preferredquality': '192'
  36.         }],
  37.         'quiet': True,
  38.         'no_warnings': True
  39.     }
  40.     #solo con $ 
  41.     #await ctx.message.delete()
  42.     with yt_dlp.YoutubeDL(ydl_opts) as ydl:
  43.         ydl.download([url])
  44.  
  45.     # Sube el archivo a un canal específico
  46.     channel = bot.get_channel(1087798657753042965)
  47.     await contex.send(content='Subiendo...')
  48.     await channel.send(file=discord.File('song.mp3'))
  49.     await contex.edit(content='Subido.')
  50.   
  51. if __name__ == '__main__':
  52.     bot.run(my_secret)

Editor

You can edit this paste and save as new:


File Description
  • Code
  • Paste Code
  • 23 Mar-2023
  • 1.49 Kb
You can Share it: