def join(self, ctx):
"""Summons the bot to your voice channel."""
msg = await ctx.send('\N{RUNNER} Connecting to voice...')
state = self.state_for(ctx.guild)
# already connected?
if state.connected:
return await msg.edit(content='I\'m already playing music in `{}`.'.format(state.channel))
# can't join if we aren't in a voice channel.
if ctx.author.voice is None:
return await msg.edit(content='I can\'t join you if you aren\'t in a voice channel.')
# the channel that the command invoker is in
ch = ctx.author.voice.channel
# check if we can join that channel.
if not ctx.guild.me.permissions_in(ch).connect:
return await msg.edit(content='\N{LOCK} I can\'t connect to that channel.')
try:
log.debug('Connecting to %s.', ch)
await ch.connect()
except TimeoutError:
await msg.edit(content='\N{ALARM CLOCK} Couldn\'t connect, I took too long to reach Discord\'s servers.')
log.warning('Timed out while connecting to Discord\'s voice servers.')
except ClientException:
await msg.edit(content='\N{CONFUSED FACE} I\'m already connected.')
log.warning('I couldn\'t detect being connected.')
else:
await msg.edit(content='\N{OK HAND SIGN} Connected!')
评论列表
文章目录