switchupcb / disgo

Create a Discord Bot in Go using this Discord API Wrapper. The next generation of Discord API Consumption.
Apache License 2.0
89 stars 2 forks source link

Incorrect Field Definition for InteractionResponse Data Interface Type #31

Closed No3371 closed 2 years ago

No3371 commented 2 years ago
// Interaction Response Structure
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-response-structure
type InteractionResponse struct {
    Type Flag                     `json:"type"`
    Data *InteractionCallbackData `json:"data,omitempty"`
}

https://stackoverflow.com/questions/44370277/type-is-pointer-to-interface-not-interface-confusion

Pointers to interfaces are almost never useful. In fact, the Go runtime was specifically changed a few versions back to no longer automatically dereference interface pointers (like it does for structure pointers), to discourage their use. In the overwhelming majority of cases, a pointer to an interface reflects a misunderstanding of how interfaces are supposed to work.

(BTW, I failed to find a way to properly respond to interaction. By newing disgo.CreateInteractionResponse I can send an empty response and that's all.)

switchupcb commented 2 years ago

Thanks for using Disgo in its Beta release. Your help is appreciated in bringing us closer to a production-ready release.

The issue with disgo.CreateInteractionResponse was related to usage of the wrong HTTP method. This has been fixed accordingly. Please note that requests which use multipart/form-data are not supported at this time (stated in https://github.com/switchupcb/disgo/releases/tag/v0.10.0). This may or may not be applicable to your use-case according to https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response. In any case, you should be able to use CreateInteractionResponse without files.

In addition to the above, an example for slash commands (interaction responses) is almost completed. Full support for the CreateInteractionResponse will be confirmed upon it's release (or #19; whichever comes first).

switchupcb commented 2 years ago

The main issue regarding tricky pointers is related to a dasgo field declaration. Issues such as these can be fixed by making a pull request on the Dasgo repository. A pull request and subsequent commit has already been completed for this issue.

However, feel free to request this issue to be re-opened (with a focus on CreateInteractionResponse) if further issues occur unexpectedly.

switchupcb commented 2 years ago

If you could not send any content in your messages, this was due to the CreateMessage using a multipart/form content type without the payload_json provided (in anticipation of support for files). Support for files has been added to Disgo in https://github.com/switchupcb/disgo/commit/b2d7844f67af28b216e4e4842387f4ff33785e36. An example has been provided at _examples/message/send.

switchupcb commented 2 years ago

The dasgo.CreateInteractionResponse structure was missing a field for the HTTP information that contained information about the response. Thus, only an empty message was sent. This occurred due to the documentation implicitly missing interaction fields. These fields have been added to dasgo.go. Based on the Slash Command Example in https://github.com/switchupcb/disgo/pull/38, interactions are working as expected now. However, you may want to wait until this is merged and released in disgo v0.10.1(which precedes disgo v10 STABLE).

switchupcb commented 2 years ago

I will send you a a small reward as courtesy of your time spent testing during disgo v0.10.0 BETA. If you are interested, let me know and I will email your connected email to GitHub (@No3371).

switchupcb commented 2 years ago

The examples have been merged: https://github.com/switchupcb/disgo/tree/v10/_examples/command.