最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Discord bot PY interactions - Stack Overflow

programmeradmin4浏览0评论

I have a problem with interactions of my discord bot in python, manually in server settings -> integrations -> (my bot) -> interaction I am able to determine what role can see this interaction, or on what channels it can be visible, when I try to do it manually in the script I am not able to. How can I do this in the script so that I don't have to do it manually and have these permissions set automatically?

I tried using some permission settings, but nothing happened, and I kept seeing this interaction. I don't mean that someone could see it, use it and receive the answer "you can't use this interaction", but that they wouldn't see it at all if they don't have this role or are not on a given channel

Under im giving u my strict interaction where i need to do this permissions

@bot.treemand(name="weryfikacja", description="Przepisz kod CAPTCHA, aby się zweryfikować.")
async def weryfikacja(interaction: discord.Interaction, kod: str):
    role = interaction.guild.get_role(ROLE_ID)
    if role and role in interaction.user.roles:
        await interaction.response.send_message("✅ Już jesteś zweryfikowany!", ephemeral=True)
        return

    user_id = interaction.user.id

    if user_id not in user_captchas:
        await interaction.response.send_message("⚠ Nie masz wygenerowanego kodu CAPTCHA. Użyj najpierw przycisku `✅ Weryfikacja`.", ephemeral=True)
        return

    if kod.upper() == user_captchas[user_id]:
        if role:
            await interaction.user.add_roles(role)
            await interaction.response.send_message("✅ Weryfikacja zakończona sukcesem! Otrzymałeś rolę.", ephemeral=True)
            del user_captchas[user_id] 
        else:
            await interaction.response.send_message("⚠ Błąd: Nie znaleziono roli!", ephemeral=True)
    else:
        await interaction.response.send_message("❌ Niepoprawny kod! Spróbuj ponownie.", ephemeral=True)

I have a problem with interactions of my discord bot in python, manually in server settings -> integrations -> (my bot) -> interaction I am able to determine what role can see this interaction, or on what channels it can be visible, when I try to do it manually in the script I am not able to. How can I do this in the script so that I don't have to do it manually and have these permissions set automatically?

I tried using some permission settings, but nothing happened, and I kept seeing this interaction. I don't mean that someone could see it, use it and receive the answer "you can't use this interaction", but that they wouldn't see it at all if they don't have this role or are not on a given channel

Under im giving u my strict interaction where i need to do this permissions

@bot.treemand(name="weryfikacja", description="Przepisz kod CAPTCHA, aby się zweryfikować.")
async def weryfikacja(interaction: discord.Interaction, kod: str):
    role = interaction.guild.get_role(ROLE_ID)
    if role and role in interaction.user.roles:
        await interaction.response.send_message("✅ Już jesteś zweryfikowany!", ephemeral=True)
        return

    user_id = interaction.user.id

    if user_id not in user_captchas:
        await interaction.response.send_message("⚠ Nie masz wygenerowanego kodu CAPTCHA. Użyj najpierw przycisku `✅ Weryfikacja`.", ephemeral=True)
        return

    if kod.upper() == user_captchas[user_id]:
        if role:
            await interaction.user.add_roles(role)
            await interaction.response.send_message("✅ Weryfikacja zakończona sukcesem! Otrzymałeś rolę.", ephemeral=True)
            del user_captchas[user_id] 
        else:
            await interaction.response.send_message("⚠ Błąd: Nie znaleziono roli!", ephemeral=True)
    else:
        await interaction.response.send_message("❌ Niepoprawny kod! Spróbuj ponownie.", ephemeral=True)
Share Improve this question asked Feb 14 at 0:52 user28857236user28857236 92 bronze badges 1
  • I'm super confused as to what you're trying to achieve – Blue Robin Commented yesterday
Add a comment  | 

2 Answers 2

Reset to default 0

Permissions for who can see a particular application command are handled via the permissions properties on the command itself, not on the interaction of a command.

As per the Discord developer documentation, you can update the command's permissions using the Edit application command permissions endpoint using an auth token for a user that has permissions to modify commands. Through here, you can set particular channels and roles that should have access to the command. Alternately, you use the Edit Guild Application Command endpoint to set the default_member_permissions property on the command to 0, which will disable the command until specific overrides are created on the server by an administrator.

As an example using requests.py, via the above documentation:

A_SPECIFIC_CHANNEL = "<channel_id>"
url = "https://discord/api/v10/applications/<application_id>/guilds/<my_guild_id>/commands/<my_command_id>/permissions"

json = {
    "permissions": [
        {
            "id": A_SPECIFIC_CHANNEL,
            "type": 3,
            "permission": False
        }
    ]
}

headers = {
    "Authorization": "Bearer <my_bearer_token>"
}

r = requests.put(url, headers=headers, json=json)

you can control who uses a command on Discord by setting permissions on the command itself, not on the interaction. Use the Discord API to update permissions, allowing or denying access to channels (type: 3) or roles (type: 1). Send a PUT request with the channel/role ID and an authentication token. Check out this example:

import requests

url = "https://discord/api/v10/applications/<app_id>/guilds/<guild_id>/commands/<command_id>/permissions"
json = {
    "permissions": [
        {
            "id": "<channel_or_role_id>",
            "type": 3,  #1 for role, 3 for channel
            "permission": False  #True to allow, False to deny
        }
    ]
}
headers = {"Authorization": "Bearer <token>"}

response = requests.put(url, headers=headers, json=json)
发布评论

评论列表(0)

  1. 暂无评论