【问题标题】:Discord.js v12.5.3 is there a way I could add role(s) on interaction?Discord.js v12.5.3 有没有办法在交互中添加角色?
【发布时间】:2021-09-08 17:53:19
【问题描述】:

我的应用系统完成了 90%,但我缺少一件事

我正在尝试在有人申请时添加角色, 我试着用这个来做

let teamRole = message.guild.roles.cache.find(role => role.id == "761996603434598460")

member.roles.add(teamRole)

但它没有添加角色(我没有得到任何错误)

我有什么方法可以使用下面的代码进行交互吗?

client.ws.on("INTERACTION_CREATE", async (interaction) => {
    // If component type is a button
    if (interaction.data.component_type === 2) {
        const guildId = interaction.guild_id;
        const userId = interaction.member.user.id;
        const buttonId = interaction.data.custom_id;
        const member = client.guilds.resolve(guildId).member(userId);
        if (buttonId == "send_application") {
            // Reply to an interaction, so we don't get "This interaction failed" error
            client.api.interactions(interaction.id, interaction.token).callback.post({
                data: {
                    type: 4,
                    data: {
                        content: "I have started the application process in your DM's.",
                        flags: 64 // make the message ephemeral
                    }
                }
            });

感谢您的帮助

【问题讨论】:

    标签: discord discord.js discord-buttons


    【解决方案1】:

    当你添加一个角色时,它应该是一个雪花值,所以你应该使用 ID 而不是它自己的角色来添加

    不正确:

    let teamRole = message.guild.roles.cache.find(role => role.id == "761996603434598460")
    
    member.roles.add(teamRole)
    

    正确:

    // using the ID Directly
    member.roles.add('761996603434598460')
    

    【讨论】:

    • 在执行此操作后发现我的代码存在问题哈哈,它在被接受时为所有应用程序添加角色,我必须考虑以不同方式处理用户交互或只是升级到 d.js v13 lmao
    • 我没有真正明白你的意思?,无论如何你可以通过 discord UltraX#0001 联系我
    猜你喜欢
    • 2020-10-24
    • 2021-09-20
    • 2021-03-30
    • 2021-07-13
    • 2021-10-12
    • 2020-11-04
    • 2020-11-30
    • 2023-03-15
    • 2021-01-28
    相关资源
    最近更新 更多