簡體   English   中英

Discord bot 不發送歡迎消息 | JS

[英]Discord bot doesn't send welcome messages | JS

所以我堅持使用 discord 機器人的歡迎功能。

它不發送任何消息。

這是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)
    })

這是 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); 

問題出在這一行:

client.channels.cache.getwelcomechannel.send(embed)

有兩個問題, getwelcomechannel不是 function,即使它是 function,你也不會調用它。

要解決此問題,您可以對通道集合使用.get()方法。

client.channels.cache.get(welcomechannel).send(embed)

問題出在 index.js 和 welcome.js 中

首先,您不包括GUILD_MEMBERS作為 index.js 中的意圖。

您在welcome.js 中的第二個問題。 getwelcomechannel不是ChannelManager的有效屬性,因此正如@bedstorm 所說,您可以使用get() function 並傳入頻道 ID。 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);
    })
}

然后只需將GUILD_MEMBERS意圖添加到您的客戶端

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM