gpt4 book ai didi

python - Discord.py - 'VoiceState' 对象没有属性 'voice_channel'

转载 作者:行者123 更新时间:2023-12-05 09:13:54 30 4
gpt4 key购买 nike

大家。我正在写一个 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()

最佳答案

在重写版本 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)

关于python - Discord.py - 'VoiceState' 对象没有属性 'voice_channel',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55321681/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com