header photo

The Journey of Hammond 214

thumbvoice4's blog

blog post

Python: Make a Discord bot (#9 - Mute/Unmute)
Hi guys and welcome back to the discord. field educational sequence. during this episode of the series we're. going to be creating a. trouble-free mute command um. which will allow anyone with the manage. messages permission. to mute someone and that'll. discontinue them from speaking um within the . channel. and also um we'll set it. surely discontinue people. talking in voice channels besides ok. so to start this off we will. create our bot dot command. and seeing as we have a custom help. command now which. needs us to offer an outline we're. going to. well it doesn't need us yet benefits. from us giving it a description. we'll supply it an outline. mute the desired. consumer. okay now we create a operate async. mute um we will desire to flow in. context. member which will be a discord. member. um megastar because we'll desire to.
Also pass in how to add a bot to discord server and. intent could be varied lines. and we are going to set the reason defaultly equal. to none. ok so the very first thing we'll. do is truly. create a guild variable and set that. equivalent to ctx. dot guild this is not essential. but. we're going to create it because we are. going to be calling guild. lots during this command. ok so then we're going to do muted. role. equals discord. dot utils. dot get. guild dot roles. call. equals muted. and in actual fact what this would do is it. will search via all the roles we. have within the discord guild. and it will be looking for the muted. function. if we do not have a um muted row oh. what is going to happen is it's going to simply go back. none. so we'll actually manage the. case people not having a muted role now. so. if no longer muted position. so clearly what is going to happen with this.

If announcement is. if there's no muted position so if this. returns. none it's going to run the code we installed here. so we will do. muted function equals. anticipate guild dot. create underscore. function. and we'll give it a similar name. as we certain up there. that's muted. okay so that will create our position but. developing the role is not good enough. what we're then going to need to do is. leaf through each channel. in our server so yeah. channels. and we will want to watch for. channel dot set. underscore permissions. and here we are able to set particular. permissions for for what we wish to. occur with the mute so. very first thing we need to do is circulate within the . um muted position so this would say. um if the person has the muted function um. set those permissions for this channel. so the first one we wish to do is communicate. equals fake that will um.
suggest that if it is a voice channel they. can not speak it. converse in that channel um you're also. going to do send. underscore messages. without a doubt fake meaning if it is a. textual content channel. capital f we need that um if it that. which clearly capability if it's a textual content. channel um. they cannot send any message. any textual content messages into the channel. um you could also do you um. study underscore message underscore. historical past. um equals fake and what that what that. will do. is it'll make it so um the user can't. examine any of the previous messages in the. channel. yet they only can't examine messages within the . channel and also we'll do. examine underscore. messages. equals. fake however. um for my case i actually do prefer them. so that it will study . messages so we will set that to actual or. you can just. remove that whole line but i'm going to.
retain it there in case i want to change. it sooner or later. okay so truly what that is doing is. actually muting the

Go Back


Blog Search


There are currently no blog comments.