Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bot.click function not working. Having the issue {"message": "Unknown Application", "code": 10002}' when interacting with buttons. #480

Open
Wert112 opened this issue Jan 22, 2024 · 0 comments

Comments

@Wert112
Copy link

Wert112 commented Jan 22, 2024

Here's issue from log

 [+] (<discum.interactions.buttons.Buttons->click) Post -> https://discord.com/api/v9/interactions
 [+] (<discum.interactions.buttons.Buttons->click) {"type": 3, "nonce": "1199132815392768000", "guild_id": "1001040169643814963", "channel_id": "1101420060603601008", "message_flags": 0, "message_id": "1199133094150676482", "application_id": "1198295772895117366", "data": {"component_type": 2, "custom_id": "giveaways:59d1f82c-d5a8-4fab-9fb2-b0f2ffbded14:enter"}, "session_id": "1Hv3NPGtWWJFZSy6dzAEP8RvpSAmNFpV"}
 [+] (<discum.interactions.buttons.Buttons->click) Response <- b'{"message": "Unknown Application", "code": 10002}'

Here's my whole code, only bot.click fuction not works, will be glad to any help

bot = discum.Client(token=discord_token, log=True)

@bot.gateway.command
def handle_message(resp):
    try:
        if resp.event.ready_supplemental:
            user = bot.gateway.session.user
            print("Logged in as {}#{}".format(user.get('username'), user.get('discriminator')))

        if resp.event.message:
            process_message(resp.parsed.auto())

    except KeyError as e:
        print(f"KeyError: {e}")

def process_message(m):
    guildID = m.get('guild_id')
    channelID = m['channel_id']
    author = m.get('author', {})
    username = author.get('username', 'Unknown')
    discriminator = author.get('discriminator', '0000')
    content = m.get('content', '')
    messageID = m['id']

    print("> guild {} channel {} | {}#{} (Message ID: {}) : {}".format(guildID, channelID, username, discriminator, messageID, content))

    if 'attachments' in m:
        attachments = m['attachments']
        print("Attachments: {}".format(attachments))

    if 'embeds' in m:
        embeds = m['embeds']
        print("Embeds: {}".format(embeds))

    process_components(m, guildID, channelID, messageID)

def process_components(m, guildID, channelID, messageID):
    if 'components' in m:
        components = m['components']
        print("Components: {}".format(components))
        button_name = "Enter"
        if components and 'components' in components[0]:
            for button in components[0]['components']:
                if button.get('label') == button_name:
                    print_button_custom_id(button)
                    click_button(m, guildID, channelID, messageID, button)

def print_button_custom_id(button):
    custom_id = button.get('custom_id')
    if custom_id:
        print("Button Custom ID:", custom_id)
    else:
        print("Button does not have a custom ID.")

def click_button(m, guildID, channelID, messageID, button):
    data = bot.getMessage(channelID, messageID).json()[0]
    buts = Buttoner(data["components"])
    custom_id = button.get('custom_id')
    if custom_id:
        bot.click(
            data["author"]["id"],
            channelID=data["channel_id"],
            guildID=guildID,
            messageID=data["id"],
            messageFlags=data["flags"],
            data=buts.getButton(customID=custom_id),
        )
    else:
        print("Button does not have a custom ID. Skipping click.")

bot.gateway.run(auto_reconnect=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant