验证机器人不添加角色

Verification Bot not adding roles

我一直被抛出 "client.guilds.get(...).member(...).roles.add is not a function" 并且我已经尝试了很多关于更改行的线程,但是 none 确实解决了我遇到的问题。

我曾尝试将 message.author 更改为 message.member,但它似乎没有用,而且给我带来了更多错误。

client.on('message', (message) => {
    if (message.author.bot || !message.author.token || message.channel.type !== `dm`) return
    if (message.content !== (verifymsg.replace('{token}', message.author.token))) return
    message.channel.send({
        embed: {
            color: Math.floor(Math.random() * (0xFFFFFF + 1)),
            description: completemsg,
            timestamp: new Date(),
            footer: {
                text: `Verification Success`
            }
        }
    })
    client.guilds.get(config.guild).member(message.author).roles.add(config.role) // ensure this is a string in the config ("")
        .then(console.log(`TOKEN: ${message.author.token} :: Role ${config.role} added to member ${message.author.id}`))
        .catch(console.error)
})

用户应该在用给定的行进行验证后获得一个角色"Member"。

正如错误所说,GuildMember.roles.add() 不是一个函数。 GuildMember.roles returns 一个 Collection,并且 add() 不是 Collection 或 Map 的方法(Collection extends Map)。

你应该使用 GuildMember.addRole().

client.guilds.get(config.guild).member(message.author).addRole(config.role)