【发布时间】:2021-02-06 19:56:22
【问题描述】:
大家好,由于某种原因,我的机器人实际上可以加入,但无法播放音频。 实际上我对此完全陌生,我试图让它像 2 小时一样工作,并设法设置加入但不玩(或离开)命令。
import os
import random
from dotenv import load_dotenv
import youtube_dl
import discord
from discord.ext import commands
from discord.ext import commands
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
players={}
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
@bot.command(name="Ja_som_to_nebol.")
async def sranda(ctx):
sranda_quotes = ["Not gonna lie, kinda sus",
("Not gonna lie, kinda sus"), ]
response = random.choice(sranda_quotes)
await ctx.send(response)
#@bot.event
#async def on_command_error(ctx, error):
# if isinstance(error, commands.errors.CheckFailure):
# await ctx.send('You do not have the correct role for this command.')
@bot.command(name="join")
async def join(ctx):
channel = ctx.author.voice.channel
await channel.connect()
@bot.command(name="leave")
async def leave(ctx):
channel = ctx.author.voice.channel
await channel.disconnect()
@bot.command(name="play")
async def play(ctx, url):
guild = ctx.author.voice.channel
voice_client = discord.utils.find(lambda c: c.guild.id == server.id, client.voice_client)
player = await voice_client.create_ytdl_player(url)
players=[server.id] = player
player.start()
bot.run(TOKEN)
【问题讨论】:
-
youtube_dl 被删除:github.com/ytdl-org/youtube-dl
标签: python python-3.x discord bots discord.py