如何使Discord机器人赋予用户角色?它具有“管理员”权限,并且我正在使用nodejs库。到目前为止,这是我的代码(这将初始化bot):
var auth = require("./auth.json");
var fs = require("fs");
var bot = new discord.Client();
bot.login("TOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKENTOKEN")
bot.on("ready", function(event) {
console.log("Initialized");
});
答案 0 :(得分:1)
您必须使用 GuildMember.addRole()函数。 (要获得公会成员,请使用 Guild#members.get())。阅读Discord.js.org文档以获取更多信息。
答案 1 :(得分:0)
您可以使用:
bot.on("message", (message) => {
if(!message.member) return
// Find the role by name
var role = message.guild.roles.find((r) => r.name === "Name of your role");
// Assign the role to the message author
message.member.roles.add(role);
});
答案 2 :(得分:0)
您可以尝试
client.on('guildMemberAdd', member => {
//Search and add the role to the new user
member.addRole(member.guild.roles.find(nm => nm.name === "Your role name"));
// Send the message to a designated channel on a server:
const channel = member.guild.channels.find(ch => ch.name === 'general');
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send the message, mentioning the member
channel.send(`Welcome to the server, ${member}`);
});