每个人。我正在写一个Discord机器人来播放声音。但我遇到了一个问题。
channel = ctx.message.author.voice.voice_channel
AttributeError: 'VoiceState' object has no attribute 'voice_channel'
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'VoiceState' object has no attribute 'voice_channel
这里有人可以帮助我吗?谢谢您的任何评论。
功能:
import asyncio
import discord, time
from discord.ext import commands
from discord.voice_client import VoiceClient
@bot.command(pass_context=True)
async def bb(ctx):
user = ctx.message.author
channel = ctx.message.author.voice.voice_channel
await bot.join_voice_channel(channel)
player = voice.create_ffmpeg_player('1.m4a')
player.start()
答案 0 :(得分:0)
在重写版本1.0中,VoiceState.voice_channel
更改为VoiceState.channel
。
如果使用的是重写版本,则以下内容足以播放文件:
from discord import FFmpegPCMAudio
from discord.utils import get
@bot.command()
async def bb(ctx):
channel = ctx.message.author.voice.channel
if not channel:
await ctx.send("You are not connected to a voice channel")
return
voice = get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
source = FFmpegPCMAudio('1.m4a')
player = voice.play(source)