[英]Welcome message with Discord.js - “Cannot read property 'get' of undefined”
I'm learning JavaScript with the Library Discord.js/Node.js and I'm building a Discord bot to exercise myself.我正在使用库Discord.js/Node.js学习 JavaScript,我正在构建一个 Discord 机器人来锻炼自己。
I'm trying to send a message to a new member of my discord server.我正在尝试向我的 Discord 服务器的新成员发送消息。 The property I was looking for was .find
, I didn't find it anywhere on the wiki of Discord.js and I've got an error that said Cannot read property 'get' of undefined
.我正在寻找的属性是.find
,我没有在 Discord.js 的 wiki 上的任何地方找到它,我有一个错误,说Cannot read property 'get' of undefined
。
So I decided to use a property that Ii found on the Wiki of Discord.js .Get
.所以我决定使用我在 Discord.js .Get
的 Wiki 上找到的一个属性。 And I've got the same error.我也有同样的错误。 I don't know how to tell to the bot to send a message to the new user when he joins the server for the first time.我不知道如何告诉机器人在他第一次加入服务器时向新用户发送消息。
Here's my code:这是我的代码:
bot.on("guildMemberAdd", MemberAdd => {
MemberAdd.guild.channel.get("enter-leave").send("HI, welcome on my server.")
console.log("enter");
});
The answer was that I've forgot the S for .channels
.答案是我忘记了.channels
的 S 。 .channel
was another property. .channel
是另一个属性。
So my code is所以我的代码是
bot.on("guildMemberAdd", MemberAdd => {
MemberAdd.guild.channels.find("name", "general").send("Bienvenu dans ma taverne mon chou :heart:.")
console.log("enter"); });
for discord.js v12 you do:对于 discord.js v12,您可以:
bot.on("guildMemberAdd", MemberAdd => {
let channel = MemberAdd.guild.channels.cache.find(channel => channel.name === "enter-leave")
channel.send("HI, welcome on my server.")
console.log("enter");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.