forked from eatplaynap/choosing-someone-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
choose.rb
32 lines (24 loc) · 838 Bytes
/
choose.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true
require 'dotenv/load'
require 'discordrb'
bot = Discordrb::Commands::CommandBot.new(
token: (ENV['TOKEN']).to_s,
prefix: '!'
)
bot.command(:you) do |event, number|
channel = event.user.voice_channel
return event.send_message('Join a voice channel before executing the command!') if channel.nil?
return event.send_message("Huh, seems like you're all muted!") if channel.users.all?(&:self_muted?)
unmuted_users = channel.users.reject(&:self_muted?)
user_names = unmuted_users.map(&:name)
chosen_users =
if number == 'all'
user_names.shuffle
else
number = number&.to_i || 1
return event.send_message('The number should be greater than 0!') unless number.positive?
user_names.sample(number)
end
event.send_message chosen_users.join(', ')
end
bot.run