Skip to content

Commit fd0eeeb

Browse files
authored
Merge pull request AnIdiotsGuide#71 from Harriiison/patch-1
Update Voice Channel Kick Example
2 parents 8d57bec + b553243 commit fd0eeeb

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

examples/miscellaneous-examples.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,34 +190,24 @@ if( swearWords.some(word => message.content.includes(word)) ) {
190190

191191
### Kicking users \(or bots\) from a voice channel
192192

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.
196194

197195
```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'])) return message.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'])) return message.reply('Missing the required `Move Members` permission.');
200198

201199
// Get the mentioned user/bot and check if they're in a voice channel:
202200
const member = message.mentions.members.first();
203201
if (!member) return message.reply('You need to @mention a user/bot to kick from the voice channel.');
204202
if (!member.voiceChannel) return message.reply('That user/bot isn\'t in a voice channel.');
205203

206-
// Now we make a temporary voice channel, move the user/bot into the channel, and delete it:
207-
const temp_channel = await message.guild.createChannel(user.id, 'voice', [
208-
{ id: guild.id,
209-
deny: ['VIEW_CHANNEL', 'CONNECT', 'SPEAK'], },
210-
{ id: member.id,
211-
deny: ['VIEW_CHANNEL', 'CONNECT', 'SPEAK'] }
212-
]);
213-
await member.setVoiceChannel(temp_channel);
214-
215-
await temp_channel.delete();
204+
// Now we set the member's voice channel to null, in other words disconnecting them from the voice channel.
205+
member.setVoiceChannel(null);
216206

217207
// Finally, pass some user response to show it all worked out:
218208
message.react('👌');
219209
/* or just "message.reply", etc.. up to you! */
220210
```
221211

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.
223213

0 commit comments

Comments
 (0)