[英]How to display discord.js greeting message?
當有人進入服務器時,我嘗試使用我的 discord.js 機器人發送問候語時遇到了一些問題。 我遵循了文檔中的所有說明,但它並沒有改變任何東西。 我的終端沒有發送錯誤,任何命令都可以使用。 我的 discord.js 版本是 12.5.3
client.on('guildMemberAdd', member => {
const lobbyChannel = member.guild.channels.find(ch => ch.name === 'lobby');
if (!lobbyChannel) return;
lobbyChannel.send(`Welcome to the server, ${member}`).catch(console.error);
});
您必須將代碼更改為此,因為.find()
方法僅存在於您可以使用member.guild.channels.cache
訪問的緩存通道中。 如果您需要新成員加入時的信息,則在聲明客戶端時還需要GUILD_MEMBERS
意圖。 除此之外,您的代碼可能如下所示:
client.on('guildMemberAdd', member => {
const lobbyChannel = member.guild.channels.cache.find(ch => ch.name === 'lobby');
if (!lobbyChannel) return;
lobbyChannel.send(`Welcome to the server, ${member}`).catch(console.error);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.