everyone. I'm writing a Discord bot, for play sound. but I'm faced with a problem.
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
Could anyone here help me please? Thank you for any comments.
Function:
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()
In the rewrite version, version 1.0, VoiceState.voice_channel was changed to VoiceState.channel.
If you are using the rewrite version, the below should be sufficient to play a file:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With