当前位置: 首页 > 知识库问答 >
问题:

Discord bot在Python的帮助下使用语音聊天来静音人们的声音

仉俊能
2023-03-14

我正在尝试制作一个Discord机器人,它使用语音聊天使参与者的声音静音。

为此,我使用Python。

这是我的代码,但它没有按预期工作。

import discord 
from discord.ext import commands 

client = commands.Bot(command_prefix=" !") 

@client.event 
async def on_ready():
     print('BOT ACTIVATED')

@client.command() 
async def mute(ctx):
     voice_client = ctx.guild.voice_client
     if not voice_client:
         return
     channel = voice_client.channel
     await voice_client.voice_state(ctx.guild.id, channel.id, self_mute=True)
 
client.run(My Token)

我的想法是:

我将输入的命令:!全部静音\

机器人将使语音聊天中的所有参与者静音

我将输入的命令:!全部取消静音\

机器人将取消语音聊天中所有参与者的静音。

共有1个答案

太叔逸春
2023-03-14

在我们找到问题的关键之前,请在前缀上写一个简短的词:
您的命令前缀是 预先使用空格。我不知道这是否是有意的,但如果是,在我的测试中,我发现使用它是不可能的。不和谐带开始空白,所以我所有的信息!测试结果为!测试

修复此问题后,请尝试使用!mute命令产生错误:
'VoiceClient'对象没有属性'voice\u state'实际上,我在文档中找不到类似的内容。我花了很多时间寻找,但我可能已经找到了你想要的。

client = commands.Bot(command_prefix="!") 

@client.command() 
async def mute(ctx):
        voice_client = ctx.guild.voice_client #get bot's current voice connection in this guild
        if not voice_client:  #if no connection...
            return  #probably should add some kind of message for the users to know why nothing is happening here, like ctx.send("I'm not in any voice channel...")
        channel = voice_client.channel #get the voice channel of the voice connection
        people = channel.members #get the members in the channel
        for person in people: #loop over those members
            if person == client.user: #if the person being checked is the bot...
                continue #skip this iteration, to avoid muting the bot
            await person.edit(mute=True, reason="{} told me to mute everyone in this channel".format(ctx.author))
            #edit the person to be muted, with a reason that shows in the audit log who invoked this command. Line is awaited because it involves sending commands ("mute this user") to the server then waiting for a response.

您的机器人需要权限才能禁用用户

 类似资料:
  • 本文向大家介绍python 实现语音聊天机器人的示例代码,包括了python 实现语音聊天机器人的示例代码的使用技巧和注意事项,需要的朋友参考一下 前言 在不远的将来,实现一定程度上的语音支持将成为日常科技的基本要求,整合了语音识别的python程序提供了其他技术无法比拟的交互性和可访问性。最重要的是,在python程序中实现语音识别非常简单。整个代码实现下来还不到150行。 原理简介 许多现代语

  • 本文向大家介绍Android仿微信语音聊天功能,包括了Android仿微信语音聊天功能的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Android仿微信语音聊天功能代码。分享给大家供大家参考。具体如下: 项目效果如下: 具体代码如下: AudioManager.java AudioRecorderButton.java DialogManager.java MainActivity.ja

  • 我需要知道如何让不和谐机器人断开语音频道。目前这是我加入语音频道的代码 我需要密码来断开与语音频道的连接

  • 问题内容: 我想编写一个脚本,在其中使用如下的selenium包: 现在,在获得所需的URL之后,我想使镶边声音静音。我该怎么办?像这样的东西: 其他任何Webdriver都有可能吗?像Firefox或…? 问题答案: 不确定是否可以在打开页面后(通常在任何页面上都可以这样做),但是可以通过设置切换器来在浏览器会话的整个过程中将所有声音静音: 或者,您可以直接将HTML5视频播放器静音: 您可能需

  • 播放音乐 还是老样子,增加一个新的指令。 点下之后出现具体的参数填写窗口。 文件:当然就是填写背景音乐的文件名了,点击右边的方块可以打开音乐文件选择窗口,NVL会把认识的音乐文件都列出来,可以直接试听。 渐入时间:当切换背景音乐时,会有一段时间的渐变,前一首音乐音量逐渐减小而后一首音量逐渐增大,就是这么个效果。不填则使用默认值1000毫秒。 交叉时间:在音乐渐变时,两首曲子一起播放的交叠时间。不填

  • 声音语言 选择影像的声音语言。