Closed Sneakyninja0129 closed 7 years ago
You're accessing the attribute move_to
of the VoiceClient class, not an instance of it. Judging by your code, this line is unnecessary anyway, as you don't have a voice client to move yet.
if voice_channel is not None:
voice_client = await client.join_voice_channel(voice_channel)
Thats not what i need. What the problem is, is i want it to be able to move channels and if it is in a channel ie: if voice_channel is not None: I want it to disconnect and join the new channel
You can use server.voice_client to obtain the voice client for a given server, if there is one. Don't try and use methods from discord.VoiceClient
directly because that is the class, not the instance.
Thats still not what i need. My bot can join any channel. But once it is in a channel i cant get it to disconnect from the voice chat
Voice clients have a move_to coroutine you can use to shift them to another channel. If you need to disconnect (you don't for this), you can use disconnect instead.
Could you write an example? Im confused about legit everything ive been coding for like 10 hours and im super tired
Those issues are not to help you with your code, but to report bugs within the library. You can join the discord api server to chat about code and stuff if you wish but please stop using github as a help desk as it spams over a thousand people's email with your inability to search the documentation.
To disconnect from the current voice channel on the server:
await message.guild.voice_client.disconnect()
To move to a new channel:
await message.guild.voice_client.move_to(voice_channel)
@AXAz0r The property is only message.guild
in rewrite, which in general you should assume users are not using unless they specify otherwise.
@Gorialis True enough, but the method is the same in async where you'd only replace .guild
with .server
Where are you getting "message".server.voice_client.disconnect()?
http://python.swaroopch.com/ (for complete beginners to programming) https://learnxinyminutes.com/docs/python3/ (for people who know programming already) https://docs.python.org/3.5/tutorial/ (for the in-between group, i.e. knows some programming but not a lot) see also: http://www.codeabbey.com/ (exercises for beginners)
Can't believe no one has answered this question. Everything given so far for the rewrite, not async version (except links to the documentation). He is using message.server
. He is not using the rewrite. Y'all are petty.
http://discordpy.readthedocs.io/en/latest/api.html#discord.VoiceClient.move_to What you're looking for is this. You need an instance of the VoiceClient. Notice the text "This client is created solely through Client.join_voice_channel() and its only purpose is to transmit voice."
This means that you need to save a reference to the voice VoiceClient somewhere. You can use this example to base off of: https://github.com/Rapptz/discord.py/blob/async/examples/playlist.py
The idea is the state of the voice connection is saved, when trying to join a channel, check if that voice connection exists ( https://github.com/Rapptz/discord.py/blob/async/examples/playlist.py#L115 ) if it does, use move_to
if it doesn't, use join_voice_channel
.
The same goes for disconnecting, you have that VoiceState saved and if you have a connected VoiceClient, disconnect.
@client.command(pass_context=True) async def joinvoice(ctx): """Joins your voice channel"""
Heres the code i have i need it to either disconnect from the voice channel or for it to move the bot to voice_channel