[英]Discord bot doesn't send welcome messages | JS
So I am stuck on the welcoming feature of my discord bot.所以我坚持使用 discord 机器人的欢迎功能。
It doesn't send any message.它不发送任何消息。
Here is the code for the welcome.js file:这是welcome.js 文件的代码:
module.exports = (client) => {
client.on("guildMemberAdd", (member) => {
const welcomechannel = '934868156399386676';
const ruleschannel = '934877916041457774';
const embed = new Discord.MessageEmbed()
.setTitle(`New member has arrived!`)
.setDescription(`Welcome to the server <@${member.id}>! Enjoy your stay and make sure to check our rules ${member.guild.channels.cache.get(ruleschannel).ToString()}! :slight_smile:`)
.setColor('#0ed42a')
.setTimestamp()
client.channels.cache.getwelcomechannel.send(embed)
})
here is the code for the index.js file:这是 index.js 文件的代码:
onst { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const config = require("./config.json");
const welcome = require("./welcome.js");
client.once('ready', () => {
console.log("Your bot is online!");
welcome(client);
});
client.login(config.token);
The problem is in this line:问题出在这一行:
client.channels.cache.getwelcomechannel.send(embed)
There are 2 issues, getwelcomechannel
is not a function, and even if it was a function, you aren't calling it.有两个问题,
getwelcomechannel
不是 function,即使它是 function,你也不会调用它。
To fix this, you can use the .get()
method on the collection of channels.要解决此问题,您可以对通道集合使用
.get()
方法。
client.channels.cache.get(welcomechannel).send(embed)
the problem is both in the index.js and the welcome.js问题出在 index.js 和 welcome.js 中
first of all your not including GUILD_MEMBERS
as an intent in index.js.首先,您不包括
GUILD_MEMBERS
作为 index.js 中的意图。
Your second issue in the welcome.js.您在welcome.js 中的第二个问题。
getwelcomechannel
is not a valid property of ChannelManager , so as @bedstorm said you can use the get() function and pass in the channel id. getwelcomechannel
不是ChannelManager的有效属性,因此正如@bedstorm 所说,您可以使用get() function 并传入频道 ID。 Your code in welcome.js should look like this Welcome.js 中的代码应如下所示
module.exports = (client) => {
client.on("guildMemberAdd", (member) => {
const welcomechannel = '934868156399386676';
const ruleschannel = '934877916041457774';
const embed = new Discord.MessageEmbed()
.setTitle(`New member has arrived!`)
.setDescription(`Welcome to the server <@${member.id}>! Enjoy your stay and make sure to check our rules <#${ruleschannel}>! :slight_smile:`)
.setColor('#0ed42a')
.setTimestamp()
client.channels.cache.get(welcomechannel).send(embed);
})
}
Then just add the GUILD_MEMBERS
intent to your client然后只需将
GUILD_MEMBERS
意图添加到您的客户端
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.