问题
I want to make my discord bot to connect to the voice channel I am when I type !join
.
i have tried to do it with the following code but i got this error:
bot: BotInstance of 'Bot' has no 'voice_client_int' memberpylint(no-member)
i found that my code is not compatible with the rewrite discord version.
@bot.command(pass_context = True)
async def join(ctx):
channel = ctx.message.author.voice.voice_channel
await bot.join_voice_channel(channel)
@bot.command(pass_context = True)
async def leave(ctx):
server = ctx.message.server
voice_client = bot.voice_client_int(server)
await voice_client.disconnect()
can someone help me?
回答1:
As stated in the migrating page, in the rewrite version, the voice connection is now a method of the VoiceChannel
model.
The pass_context
is also deprecated as context is now always passed.
It now would look like this:
@bot.command()
async def join(ctx):
channel = ctx.author.voice.channel
await channel.connect()
@bot.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
Of course this oversimplified version lacks error handling.
来源:https://stackoverflow.com/questions/57285423/how-a-discord-bot-can-join-a-voice-channel-in-discord-rewrite