· 4 years ago · Aug 09, 2021, 07:32 PM
1import * as Discordeno from 'https://deno.land/x/discordeno@12.0.1/mod.ts'
2
3// Put into eventHandlers: messageCreate
4if(msg.content.toLowerCase().startsWith('!roulette') {
5 const hasPerms = await Discordeno.hasGuildPermissions(msg.guildId, Discordeno.botId, ['VIEW_CHANNEL', 'MOVE_MEMBERS'])
6 if(!hasPerms) {
7 return
8 }
9
10 // Get the guild, automatically try both cache and api if cache fails
11 const guild = Discordeno.cache.guilds.get(msg.guildId) || await Discordeno.getGuild(msg.guildId)
12
13 // Attempt to get the voice data (may not exist)
14 const memberVoiceData = guild.voiceStates.get(msg.authorId)
15
16 // Handle the case in which the voice data doesn't exist
17 if(!memberVoiceData || !memberVoiceData.channelId) {
18 return
19 }
20
21 const channel = Discordeno.cache.channels.get(memberVoiceData.channelId) || await Discordeno.getChannel(memberVoiceData.channelId)
22
23 const noBots = channel.connectedMembers?.filter((val: Discordeno.DiscordenoMember | undefined, _key: bigint): boolean => {
24 if(val)
25 return !val.bot
26 else
27 return false
28 })
29
30 if(!noBots) {
31 return
32 }
33
34 const chosen = noBots?.random()
35
36 if(!chosen) {
37 return
38 }
39
40 console.log(msg, `:poop: <@${msg.authorId}> kicked <@${chosen.id}>`)
41}