作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家。我正在写一个 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/
大家。我正在写一个 Discord 机器人,用于播放声音。但我遇到了一个问题。 channel = ctx.message.author.voice.voice_channel Attribu
我是一名优秀的程序员,十分优秀!