discord / discord-api-docs

Official Discord API Documentation
https://discord.com/developers/docs/intro
Other
5.95k stars 1.26k forks source link

Permissions in message update event sent as a number #6862

Open sebm253 opened 5 months ago

sebm253 commented 5 months ago

Description

My bot received a message update event containing resolved data of a role which had its permissions sent as a number, rather than a string as documented. This is obviously breaking behavior and should be looked into.

Formatted payload (removed all IDs except the one of Dank Memer): ```json { "webhook_id": "270904126974590976", "type": 19, "tts": false, "timestamp": "2024-04-07T02:21:40.376000+00:00", "resolved": { "roles": { "123456789": { "unicode_emoji": null, "position": 81, "permissions_new": "138538465099775", "permissions": 2147483647, "name": "bot tester", "mentionable": false, "managed": false, "id": "123456789", "icon": null, "hoist": false, "flags": 0, "description": null, "color": 15158332 } } }, "position": 0, "pinned": false, "message_reference": { "type": 0, "message_id": "123456789", "guild_id": "123456789", "channel_id": "123456789" }, "mentions": [], "mention_roles": [], "mention_everyone": false, "member": { "roles": [ "123456789" ], "premium_since": null, "pending": false, "nick": null, "mute": false, "joined_at": "2024-03-19T13:49:24.627093+00:00", "flags": 0, "deaf": false, "communication_disabled_until": null, "avatar": null }, "interaction_metadata": { "user_id": "123456789", "user": { "username": "username", "public_flags": 4194560, "id": "123456789", "global_name": "name", "discriminator": "0", "clan": null, "avatar_decoration_data": null, "avatar": "2ead157d38725eddef5b496f5a549caf" }, "type": 3, "interacted_message_id": "123456789", "id": "123456789", "authorizing_integration_owners": { "0": "123456789" } }, "id": "123456789", "flags": 0, "embeds": [ { "type": "rich", "title": "Events Manager", "fields": [ { "value": "<@&123456789>", "name": "Current", "inline": true } ], "description": "> Select a role that will be in charge of managing events in your server.", "content_scan_version": 0, "color": 2829617 } ], "edited_timestamp": "2024-05-13T06:44:32.664344+00:00", "content": "", "components": [ { "type": 1, "components": [ { "type": 3, "options": [ { "value": "bankrobbing", "label": "Bank Robbing", "emoji": { "name": "emptyspace", "id": "123456789" }, "description": "Disable Bankrobbing" }, { "value": "eventsManagerID", "label": "Events Manager", "emoji": { "name": "Menu", "id": "123456789" }, "description": "Event manager role", "default": true }, { "value": "randomEvents", "label": "Random Events", "emoji": { "name": "emptyspace", "id": "123456789" }, "description": "Spawn random events" }, { "value": "robProtection", "label": "Rob Protection", "emoji": { "name": "emptyspace", "id": "123456789" }, "description": "24h rob protection from raiders" }, { "value": "robbing", "label": "Robbing", "emoji": { "name": "emptyspace", "id": "123456789" }, "description": "Disable robbing" } ], "min_values": 1, "max_values": 1, "custom_id": "server-settings-select:123456789" } ] }, { "type": 1, "components": [ { "type": 6, "min_values": 1, "max_values": 1, "default_values": [ { "type": "role", "id": "123456789" } ], "custom_id": "server-settings-edit-role:123456789:eventsManagerID" } ] } ], "channel_id": "123456789", "author": { "username": "Dank Memer", "public_flags": 589824, "id": "270904126974590976", "global_name": null, "discriminator": "5192", "clan": null, "bot": true, "avatar_decoration_data": null, "avatar": "a_24778db4737114253ac3b30f45f1979f" }, "attachments": [], "application_id": "270904126974590976", "guild_id": "123456789" } ```

Steps to Reproduce

N/A

Expected Behavior

The permissions field is sent as a string, as documented

Current Behavior

The permissions field was sent as a number

Screenshots/Videos

No response

Client and System Information

API v10 (https://github.com/disgoorg/disgo)

MCausc78 commented 5 months ago

are you sure that you're using api v10? permissions_new doesn't exist on >v7

sebm253 commented 5 months ago

are you sure that you're using api v10? permissions_new doesn't exist on >v7

I'm using https://github.com/disgoorg/disgo which is running on API v10, yes

MCausc78 commented 5 months ago

can you send steps that reproduce this problem? i used discord.py (v2.4, master branch) but doesn't seem to reproducible for me with editing origin message as response to interaction, nor usual edit channel message

sebm253 commented 5 months ago

can you send steps that reproduce this problem? i used discord.py (v2.4, master branch) but doesn't seem to reproducible for me with editing origin message as response to interaction, nor usual edit channel message

not right now, no. this event was caused by a 3rd party bot (Dank Memer)

MCausc78 commented 5 months ago

looks if responder uses api v7, >=v8 receivers will get same payload as v7:

from discord import ui

class Setup(ui.View):
    @ui.select(placeholder='Setting', options=[
        discord.SelectOption(label='Foo', value='foo'),
        discord.SelectOption(label='Events', value='bar')
    ])
    async def setting(self, interaction: discord.Interaction, select: ui.Select):
        if select.values[0] == 'bar':
            await interaction.response.edit_message(view=EventsSetup())
        elif select.values[0] == 'foo':
            await interaction.response.edit_message(content='LGTM')

class EventsSetup(Setup):
    @ui.select(cls=ui.RoleSelect, placeholder='Select roles lol')
    async def select_roles(self, interaction: discord.Interaction, select: ui.RoleSelect):
        self.select_roles.default_values = select.values
        await interaction.response.edit_message(content='imagine bugs', view=self)

class Welcome(ui.View):
    @ui.button(label='Set up me lol')
    async def foo(self, interaction: discord.Interaction, _):
        await interaction.response.send_message(content='Please setup me lol', view=Setup())

print('\n'*100)
discord.http.Route.BASE = 'https://discord.com/api/v7'
await _ctx.send(view=Welcome())