如何在代码中解决这些错误?

时间:2018-04-04 23:25:56

标签: node.js bots discord discord.js

bot.on('guildMemberAdd', (guildMember, channel, message) => {
guildMember.addRole(guildMember.guild.roles.find(role => role.name === "ew"));
    embed = new discord.RichEmbed()
        .setTitle("User Join Notification")
        .setDescription("**guildMember.username** has joined this server.")
        .setColor("#21a1e1")
    message.channel.id('430681100956991511').sendEmbed(embed);
});

当我执行此代码时,当用户加入时,它会在控制台中报告 TypeError:无法读取属性' channel'未定义的。我怎么能解决这个问题?

感谢。

1 个答案:

答案 0 :(得分:0)

Traceback (most recent call last): File "so.py", line 6, in <module> parse(line.encode()) struct.error: unpack_from requires a buffer of at least 1164 bytes 事件only provides you with the GuildMember object,因此您的guildMemberAddchannel变量未定义。

相反,您希望让频道通过message对象发送嵌入:

GuildMember

我相信