- import discord
- import os
- from discord import app_commands
- from discord.ext import commands
- import yt_dlp
- Id = os.environ['Id']
- my_secret = os.environ['TOKEN']
- bot = discord.Client(intents=discord.Intents.default())
- tree = app_commands.CommandTree(bot)
- Guild = discord.Object(id=Id)
- @bot.event
- async def on_ready():
- await tree.sync(guild=discord.Object(id=Id))
- channel = bot.get_channel(1086317826228367461)
- await channel.send("connected")
- print("Ready!")
- @tree.command(name="hello", description="Greet me", guild=Guild)
- async def hello(contex, url: str):
- print("downloading")
- # Muestra una rueda de carga mientras se descarga la música
- loading_message = await contex.response.send_message('Cargando...')
- # Descarga la música utilizando yt-dlp
- ydl_opts = {
- 'format': 'bestaudio/best',
- 'outtmpl': 'song',
- 'postprocessors': [{
- 'key': 'FFmpegExtractAudio',
- 'preferredcodec': 'mp3',
- 'preferredquality': '192'
- }],
- 'quiet': True,
- 'no_warnings': True
- }
- #solo con $
- #await ctx.message.delete()
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
- ydl.download([url])
- # Sube el archivo a un canal específico
- channel = bot.get_channel(1087798657753042965)
- await contex.send(content='Subiendo...')
- await channel.send(file=discord.File('song.mp3'))
- await contex.edit(content='Subido.')
- if __name__ == '__main__':
- bot.run(my_secret)
[text] Code
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: