机器人拒绝连接到语音通道,而在控制台或任何地方都没有错误,在我看来,它只是挂在voice_clients = await msg.author.voic.channel.connect()
请帮助解决这个问题。
import discord
import os
import asyncio
import youtube_dl
from discord import *
intents = discord.Intents.default()
intents.message_content = True
intents.voice_states = True
client = discord.Client(intents=intents)
key = "MTA3ODY3OTcxOTIxMTQ0MjI5Nw.Gqtubx.SYqVZ7dwl8U3MpIK5mSIfXOSIi2qychJ0iddko"
voice_clients = {}
yt_dl_opts = {'format': 'bestaudio/best'}
ytdl = youtube_dl.YoutubeDL(yt_dl_opts)
ffmpeg_options = {'options': "-vn"}
@client.event
async def on_ready():
print(f"GOTOVO KAPITAN{client.user}")
@client.event
async def on_massage(msg):
if msg.content.startswith("?play"):
try:
voice_clients = await msg.author.voic.channel.connect()
voice_clients[voice_clients.guild.id] = voice_clients
url = msg.content.split()[1]
loop = asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False) )
song = data['url']
player = discord.FFmpegPCMAudio(song, **ffmpeg_options, executable="C:\\ffmpeg\\bin\\ffmpeg.exe")
voice_clients[msg.guild.id].play(player)
except Exception as err:
print(err)
if msg.content.startswith("?pause"):
try:
voice_clients[msg.guild.id].pause()
except Exception as err:
print(err)
if msg.content.startswith("?resume"):
try:
voice_clients[msg.guild.id].resume()
except Exception as err:
print(err)
if msg.content.startswich("?stop"):
try:
voice_clients[msg.guild.id].stop()
await voice_clients[msg.guild.id].disconnect()
except Exception as err:
print(err)
client.run(key)
我在很多论坛上看到了很多类似的情况,但我仍然不明白为什么会发生这种情况,以及如何解决它,在我阅读这段代码的视频中,一切都解决了,我重写了几次。(我是Python新手,如果这是一个太容易的错误,请原谅)
1条答案
按热度按时间egdjgwm81#
看起来你拼错了
on_massage
,我相信msg.author.voic.channel
应该是msg.author.voice.channel
。