You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Kicking users \(or bots\) from a voice channel
192
192
193
-
Being able to kick a user or bot from a voice channel doesn't come within Discord sadly, and it's a great feature to have for general use, or if your developing a music bot or related that needs to be removed quickly. Luckily, there's a simple and fast way to do it, and it can be added easily.
194
-
195
-
On a quick note, your message event **must be async**. This means that your `client.on('message', message ..` must include the `async` keyword, ie. `client.on('message', async message ..`, to avoid the using async in a non-async function error.
193
+
Support for kicking members from voice channels has now been added by Discord and can be achieved by doing the following.
196
194
197
195
```javascript
198
-
// Make sure the bot user has permissions to make channels and move members in the guild:
199
-
if (!message.guild.me.hasPermission(['MANAGE_CHANNELS', 'MOVE_MEMBERS'])) returnmessage.reply('Missing the required `Manage Channels` and `Move Members` permissions.');
196
+
// Make sure the bot user has permissions to move members in the guild:
197
+
if (!message.guild.me.hasPermission(['MANAGE_CHANNELS', 'MOVE_MEMBERS'])) returnmessage.reply('Missing the required `Move Members` permission.');
200
198
201
199
// Get the mentioned user/bot and check if they're in a voice channel:
202
200
constmember=message.mentions.members.first();
203
201
if (!member) returnmessage.reply('You need to @mention a user/bot to kick from the voice channel.');
204
202
if (!member.voiceChannel) returnmessage.reply('That user/bot isn\'t in a voice channel.');
205
203
206
-
// Now we make a temporary voice channel, move the user/bot into the channel, and delete it:
// Now we set the member's voice channel to null, in other words disconnecting them from the voice channel.
205
+
member.setVoiceChannel(null);
216
206
217
207
// Finally, pass some user response to show it all worked out:
218
208
message.react('👌');
219
209
/* or just "message.reply", etc.. up to you! */
220
210
```
221
211
222
-
The base idea behind this is to make a voice channel and move the user you want to "vckick" into there. Once they are there, deleting the channel will also make them leave it, and therefore be kicked.
212
+
This does the same as clicking the disconnect button on a user or bot while they are in a voice channel.
0 commit comments