I am trying to make a Discord bot that mutes the voice of the participant using voice chat.
For this, I am using Python.
This is my code, but it is not working as expected.
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)
The idea I have is:
Command I will enter: !muteall
\
And the bot will mute all the participants in the voice chat
Command I will enter: !unmuteall
\
And the bot will unmute all the participants in the voice chat.
@client.command()
decorator aboveasync def mute
? What ismain_ws
supposed to be invoice_client.main_ws.voice_state()
? I can't find it in the discord.py docs – Allisterimport 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)
– Eshan