Sha256: 18c68c1ad944cc1a02304757e44fe438405a4a46e29a802c870022a4fdc35b06
Contents?: true
Size: 1.07 KB
Versions: 4
Compression:
Stored size: 1.07 KB
Contents
# frozen_string_literal: true require "discorb" client = Discorb::Client.new def convert_role(guild, string) guild.roles.find do |role| role.id == string || role.name == string || role.mention == string end end client.once :standby do puts "Logged in as #{client.user}" end client.on :message do |message| next if message.author.bot? next unless message.content.start_with?("!auth ") role_name = message.content.delete_prefix("!auth ") role = convert_role(message.guild, role_name) if role.nil? message.reply("Unknown role: #{role_name}").wait next end message.channel.post( "Click this button if you are human:", components: [ Discorb::Button.new( "Get role", custom_id: "auth:#{role.id}", ), ], ) end client.on :button_click do |response| if response.custom_id.start_with?("auth:") id = response.custom_id.delete_prefix("auth:") response.user.add_role(id).wait response.post("You got your role!\nHere's your role: <@&#{id}>", ephemeral: true) end end client.run(ENV.fetch("DISCORD_BOT_TOKEN", nil))
Version data entries
4 entries across 4 versions & 1 rubygems