class Discorb::Command::Command::SlashCommand
Represents the slash command.
Attributes
description[R]
@return [String] The description of the command.
options[R]
@return [Hash{String => Hash}] The options of the command.
Public Class Methods
new(name, description, options, guild_ids, block, type, parent)
click to toggle source
@!visibility private
# File lib/discorb/command.rb, line 176 def initialize(name, description, options, guild_ids, block, type, parent) @description = description @name = name @guild_ids = guild_ids.map(&:to_s) @block = block @type = Discorb::Command::Command.types[type] @type_raw = 1 @options = options @id = nil @parent = parent @id_map = Discorb::Dictionary.new end
Public Instance Methods
to_hash()
click to toggle source
@!visibility private
# File lib/discorb/command.rb, line 199 def to_hash options_payload = options.map do |name, value| ret = { type: case value[:type] when String, :string, :str 3 when Integer, :integer, :int 4 when TrueClass, FalseClass, :boolean, :bool 5 when Discorb::User, Discorb::Member, :user, :member 6 when Discorb::Channel, :channel 7 when Discorb::Role, :role 8 when :mentionable 9 when Float, :float 10 else raise ArgumentError, "Invalid option type: #{value[:type]}" end, name: name, description: value[:description], required: !value[:optional], } if value[:choices] ret[:choices] = value[:choices].map { |t| { name: t[0], value: t[1] } } end ret end { name: @name, default_permission: true, description: @description, options: options_payload, } end
to_s()
click to toggle source
Returns the commands name.
@return [String] The name of the command.
# File lib/discorb/command.rb, line 194 def to_s (@parent + " " + @name).strip end