nonebot / adapter-discord

NoneBot2 Discord 适配器 / Discord adapter for nonebot2
20 stars 6 forks source link

Event has no context! #23

Open paul-sama opened 4 months ago

paul-sama commented 4 months ago

按插件实例里的 on_slash_command 情况下 event.get_user_id() 会报错

CMHopeSunshine commented 4 months ago

试试 0.1.7

paul-sama commented 4 months ago

试试 0.1.7

私聊能用了, 其他channel还是会报错

Autuamn commented 4 months ago

能发 log 吗

Interaction Object 里,user 本就是可选项
see https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-structure


我收到的包

```json { "version": 1, "type": 2, "token": "xxx", "member": { "user": { "username": "autuamn_end", "public_flags": 0, "id": "474564749217234954", "global_name": "Autuamn End", "discriminator": "0", "clan": None, "avatar_decoration_data": None, "avatar": "7a8c1eacb63acfd711543f86244e5572", }, "unusual_dm_activity_until": None, "roles": [ "1180878026678993048", "1181071825208360960", "1181071750851727442", "1180870446959296533", ], "premium_since": None, "permissions": "1125899906842623", "pending": False, "nick": None, "mute": False, "joined_at": "2023-11-07T03:44:23.842000+00:00", "flags": 2, "deaf": False, "communication_disabled_until": None, "avatar": None, }, "locale": "zh-CN", "id": "1230748389587681290", "guild_locale": "zh-CN", "guild_id": "1171294052839333910", "guild": { "locale": "zh-CN", "id": "1171294052839333910", "features": [ "ENABLED_MODERATION_EXPERIENCE_FOR_NON_COMMUNITY", "COMMUNITY", "GUILD_ONBOARDING", "GUILD_ONBOARDING_HAS_PROMPTS", "CHANNEL_ICON_EMOJIS_GENERATED", "NEWS", "GUILD_ONBOARDING_EVER_ENABLED", ], }, "entitlements": [], "entitlement_sku_ids": [], "data": { "type": 1, "options": [{"value": "123", "type": 3, "name": "字符串"}], "name": "echo", "id": "1208353258297364520", }, "channel_id": "1208348399263285308", "channel": { "type": 0, "topic": None, "theme_color": None, "rate_limit_per_user": 0, "position": 21, "permissions": "1125899906842623", "parent_id": "1180921939452244059", "nsfw": False, "name": "test", "last_message_id": "1230743594088796232", "id": "1208348399263285308", "icon_emoji": {"name": "🌐", "id": None}, "guild_id": "1171294052839333910", "flags": 0, }, "application_id": "1208326638673330196", "app_permissions": "1125899906842623", } ```

paul-sama commented 4 months ago

频道里使用 on_slash_command event 拿不到用户信息吗? event是下面这样,信息都在member.user 里面

{
    'id': 11111111111111111,
    'application_id': 11111111111111,
    'type': '<InteractionType.APPLICATION_COMMAND: 2>',
    'data': {
        'id': 1111111111111111,
        'name': '_last',
        'type': '<ApplicationCommandType.CHAT_INPUT: 1>',
        'resolved': '<UNSET>',
        'options': [
            {'name': 'battle',
             'type': '<ApplicationCommandOptionType.SUB_COMMAND: 1>',
             'value': '<UNSET>',
             'options': [],
             'focused': '<UNSET>'
             }
        ], 'guild_id': ' <UNSET>', 'target_id': '<UNSET>'
    },
    'guild_id': 11111111111111111,
    'channel': {
        'id': 11111111111111111,
        'type': '<ChannelType.GUILD_TEXT: 0>',
        'guild_id': 1111111111111111,
        'position': 1,
        'permission_overwrites': '<UNSET>',
        'name': 'x', 'topic': None, 'nsfw': False,
        'last_message_id': 11111111111111111,
        'bitrate': '<UNSET>',
        'user_limit': '<UNSET>',
        'rate_limit_per_user': 0,
        'recipients': '<UNSET>', 'icon': '<UNSET>',
        'owner_id': '<UNSET>', 'application_id': '<UNSET>',
        'managed': '<UNSET>',
        'parent_id': 111111111111111111111,
        'last_pin_timestamp': '<UNSET>', 'rtc_region': '<UNSET>',
        'video_quality_mode': ' <UNSET>',
        'message_count': '<UNSET>',
        'member_count': '<UNSET>', 'thread_metadata': '<UNSET>',
        'member': '<UNSET>',
        'default_auto_archive_duration': '<UNSET>',
        'permissions': '1125899906842623',
        'flags': '<ChannelFlags.0: 0>', 'total_message_sent': '<UNSET>',
        'available_tags': '<UNSET>', 'applied_tags': '<UNSET>', 'default_reaction_emoji': '<UNSET>',
        'default_thread_rate_limit_per_user': '<UNSET>',
        'default_sort_order': '<UNSET>', 'default_forum_layout': '<UNSET>'},
    'channel_id': 111111111111111111,
    'member': {'user':
                   {'id': 11111111111111111111,
                    'username': 'paul_sama', 'discriminator': '0',
                    'global_name': 'Paul Sama', 'avatar': None, 'bot': '<UNSET>',
                    'system': '<UNSET>', 'mfa_enabled': '<UNSET>', 'banner': '<UNSET>',
                    'accent_color': '<UNSET>', 'locale': '<UNSET>', 'verified': '<UNSET>', 'email': '<UNSET>',
                    'flags': '<UNSET>', 'premium_type': '<UNSET>', 'public_flags': '<UserFlags.0: 0>',
                    'avatar_decoration': '<UNSET>'}, 'nick': None, 'avatar': None, 'roles': [], 'joined_at': '',
               'premium_since': None, 'deaf': False, 'mute': False, 'flags': '<GuildMemberFlags.0: 0>',
               'pending': False, 'permissions': '1125899906842623', 'communication_disabled_until': None},
    'user': '<UNSET>', 'token': 'xxxxxxxxxxxxxxxxxx', 'version': 1, 'message': '<UNSET>',
    'app_permissions': '1125899906842623', 'locale': 'en-US', 'guild_locale': 'en-US',
    'timestamp': 'datetime.datetime(2024, 4, 19, 16, 23, 53, 342990)',
    'guild': {'locale': 'en-US', 'id': '479180396685426688', 'features': []}, 'entitlements': [],
    'entitlement_sku_ids': []
}
Autuamn commented 4 months ago

破案了。在频道里用只发 member,私信才发 user image

see https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-structure