简体   繁体   English

断开我的机器人与语音通道 discord.py 的连接

[英]Disconnecting my bot from Voice channel discord.py

I am giving my bot music aspects, and I am working on joining and leaving voice channels.我正在提供我的机器人音乐方面,我正在努力加入和离开语音频道。

I have searched a lot on the internet before asking, from Stack Overflow, Reddit etc. However, none of these solutions worked or were what I needed.在询问之前,我在互联网上搜索了很多,来自 Stack Overflow、Reddit 等。但是,这些解决方案都没有奏效,也不是我需要的。

My code:我的代码:

@commands.command(pass_context=True)
    async def disconnect(self, ctx):
        server = ctx.message.guild.voice_client
        await server.disconnect()

Things to note:注意事项:

This code is from StackOverflow, yet it doesn't work, my original code didn't work either此代码来自 StackOverflow,但它不起作用,我的原始代码也不起作用

This is in a seperate file from my join command这是与我的 join 命令分开的文件

However I am using cogs, and I have used heritage to basically link the 2, so even if they are in seperate files (For organization resaons), they are still part of the same class (cog) called music.但是,我使用的是齿轮,并且我已经使用传统来基本上将这两个链接起来,因此即使它们在单独的文件中(对于组织原因),它们仍然属于称为音乐的同一类(齿轮)的一部分。

How should I fix my code or change it so that it works?我应该如何修复我的代码或更改它以使其正常工作? Thanks!谢谢!

This is related to GTTS but still relevant to your cause and also features some handling for the errors thrown by the library.这与 GTTS 相关,但仍与您的原因相关,并且还对库引发的错误进行了一些处理。 See here这里

这在这里应该有效: await ctx.voice_client.disconnect()我不确定,因为我还没有测试过,但我很确定它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM