Discord.py discord 1.0.1的小问题让机器人离开
现在我有这个Discord.py discord 1.0.1的小问题让机器人离开,discord.py,Discord.py,现在我有这个 @client.command() async def comrade(ctx, amountt=30): if not ctx.message.author.voice: await ctx.send("You are not connected to a voice channel") return else: channel = ctx.message.author.voice.ch
@client.command()
async def comrade(ctx, amountt=30):
if not ctx.message.author.voice:
await ctx.send("You are not connected to a voice channel")
return
else:
channel = ctx.message.author.voice.channel
vc = await channel.connect()
vc.play(discord.FFmpegPCMAudio('songs.mp3'))
但如果机器人已经连接到语音频道,我想不出如何让它离开
我也试过这个,但不起作用:
def is_connected(ctx):
voice_client = get(ctx.bot.voice_clients, guild=ctx.guild)
return voice_client and voice_client.is_connected()
我看不出您的代码中有任何错误,但离开频道的最简单方法是下一个:
异步def离开(ctx):
voice=ctx.voice_client#每个公会只能有一个vc客户端,这就是为什么这是有效的
如果语音为“无”:
#机器人不在语音频道中
return wait ctx.send(“机器人不在语音通道中”)
#离开英吉利海峡
等待语音。断开连接()
参考: