Discord.js机器人程序“ guildMember.addRole不是函数”(已修复)

时间:2020-01-05 17:24:07

标签: javascript discord discord.js

因此,我试图更改加入服务器的用户的角色,但一直说addRole不是函数。我当前正在使用Discord.js版本11.5.1,因此我不必使用guildMember.roles.add正确吗?我不知道为什么这不起作用,我在网上找不到任何东西可以解决这个问题。如果您需要更多信息,请告诉我。

代码如下:

var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
var mongo = require('mongodb');
var db = require('./db.js');
var serverIds = require('./serverIds.js');

// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
    colorize: true
});
logger.level = 'debug';

// Initialize Discord Bot
var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});

bot.on('guildMemberAdd', (guildMember) => {
    try {
        guildMember.addRole('663290242073100309');
    } catch (e) {
        console.log(guildMember);
    }
});

这是终端中的错误:

Nicks-MacBook-Pro-2:pokemon victory road bot nick$ node bot.js
Connected
{"message":"Connected","level":"info"}
{"message":"Logged in as: ","level":"info"}
{"message":"Professor Magnolia - (663188794740178957)","level":"info"}
TypeError: guildMember.addRole is not a function
    at DiscordClient.<anonymous> (/Users/nick/Desktop/Pokemon Victory Road Bot/bot.js:65:21)
    at DiscordClient.emit (events.js:210:5)
    at emit (/Users/nick/Desktop/Pokemon Victory Road Bot/node_modules/discord.io/lib/index.js:1580:14)
    at DiscordClient.handleWSMessage (/Users/nick/Desktop/Pokemon Victory Road Bot/node_modules/discord.io/lib/index.js:1904:11)
    at WebSocket.emit (events.js:210:5)
    at Receiver.ontext (/Users/nick/Desktop/Pokemon Victory Road Bot/node_modules/ws/lib/WebSocket.js:841:10)
    at /Users/nick/Desktop/Pokemon Victory Road Bot/node_modules/ws/lib/Receiver.js:536:18
    at Receiver.applyExtensions (/Users/nick/Desktop/Pokemon Victory Road Bot/node_modules/ws/lib/Receiver.js:371:5)
    at /Users/nick/Desktop/Pokemon Victory Road Bot/node_modules/ws/lib/Receiver.js:508:14
    at Receiver.flush (/Users/nick/Desktop/Pokemon Victory Road Bot/node_modules/ws/lib/Receiver.js:347:3)

1 个答案:

答案 0 :(得分:0)

所以我发现了我的问题。我正在使用Discord.io而不是Discord.js smh。我是制作机器人的新手,所以我没意识到有什么区别,而我开始学习的教程也没有