当我在 Javascript 中输入某个短语时,我如何制作一个简单地给我一个角色的 discord 机器人?

How do i make a discord bot that simply gives me a role when i type a certain phrase in Javascript?

我已经完成了 tonstons 的搜索,但它们都是超级复杂的代码,例如,当我说“!Role (role)" 然后它给了我指定的角色。然而,我正在寻找的是更简单的东西,比如如果我说“你好”,那么机器人会给我代码中的角色。

我也尝试了很多复杂的,但大多数都使用了“addRole”函数,但输出不喜欢它

你觉得你能帮我解决这个问题吗?

Discord JS V12:

client.on("message", (message) => {
    // Checking if the message equals to "hello".
    // Since we use .toLowerCase() which converts any uppercase letter to lowercase, HeLLo will result in hello.
    if (message.content.toLowerCase() == "hello") {
        // Trying to find the role by ID.
        const Role = message.guild.roles.cache.get("RoleID");
        // Checking if the role exists.
        if (!Role) { // The role doesn't exist.
            message.channel.send(`I'm sorry, the role doesn't exist.`);
        } else { // The role exists.
            // Adding the role to the user.
            message.member.roles.add(Role).catch((error) => {console.error(error)});
            message.channel.send(`You received the role ${Role.name}.`);
        };
    }
});

Discord JS V11:

client.on("message", (message) => {
    if (message.content.toLowerCase() == "hello") {
        const Role = message.guild.roles.get("RoleID");
        if (!Role) {
            message.channel.send(`I'm sorry, the role doesn't exist.`);
        } else {
            message.member.addRole(Role).catch((error) => {console.error(error)})
            message.channel.send(`You received the role ${Role.name}.`);
        };
    }
});