shardlab / discordrb

Discord API for Ruby
MIT License
536 stars 98 forks source link

Buttons (and string selects) without emojis broken due to a Discord API change (easy fix) #247

Closed edelkas closed 10 months ago

edelkas commented 10 months ago

Description:

Starting today, buttons and string select options without explicit emojis are failing, returning the following error:

Invalid Form Body
    - components[0].components[0].emoji.name: Invalid emoji
Backtrace:
/.../lib/discordrb/api.rb:124:in `rescue in request'
/.../lib/discordrb/api.rb:113:in `request'
/.../lib/discordrb/api/channel.rb:92:in `create_message'
/.../lib/discordrb/bot.rb:405:in `send_message'
/.../lib/discordrb/data/channel.rb:433:in `send_message'
...

The issue appears to be that {} is no longer accepted as a default value for the emoji field, instead requiring an explicit null value.

Solution:

An easy tested fix is just to add the extra case

when nil
  nil

in the button builder: https://github.com/shardlab/discordrb/blob/0f01116c3326e4784a0b581326307f5a2b57427a/lib/discordrb/webhooks/view.rb#L48-L53 The same fix works for string select options here: https://github.com/shardlab/discordrb/blob/0f01116c3326e4784a0b581326307f5a2b57427a/lib/discordrb/webhooks/view.rb#L148-L153

dollerbill commented 10 months ago

@edelkas great job finding a fix so quickly, you should submit a pr for this

wouterdedroog commented 10 months ago

Ah, this is why. Does anyone know whether there's a fix that doesn't involve messing with the Discordrb code?

danbopes commented 6 months ago

Can we please roll this into a new release...I ran into this issue today.

wouterdedroog commented 6 months ago

Can we please roll this into a new release...I ran into this issue today.

It's fixed in the main branch, so if you're using bundler you should be able to add something like this to your Gemfile:

gem 'discordrb', '~> 3.5', git: 'https://github.com/shardlab/discordrb', branch: 'main'
danbopes commented 6 months ago

Yeah, that's what I ended up doing (Although I pinned it at a certain commit). Just annoying is all.

4 months in limbo, and the events api sadly still not merged in. Made development and learning rails fun for me :(