我正在尝试创建一个语音通道,以显示服务器上的成员数量,但是我似乎无法获得更改该通道的ID。我在guildMemberAdd
事件中有以下代码:
bot.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.find(ch => ch.name === 'factions');
channel.send(`Welcome to the server, <@${member.id}>! Make sure to check out <#757221255198802051> and <#757221255198802051>!`);
const serverCount = (bot.guilds.cache.get(member.guild.id).memberCount);
member.guild.channels.find(ch => ch.name === "Server Count:").setName(`Server Count: ${serverCount}`);
});
由于member.guild.channels.find is not a function
,所有这些都与最后一行分开。我知道我需要做channel.setName
,但是我不确定如何获取通道来设置传递给member
事件的guildMemberAdd
对象的名称。
答案 0 :(得分:1)
您忘记了cache
和startsWith()
这两个功能。要解决您的问题,
bot.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.find(ch => ch.name === 'factions');
channel.send(`Welcome to the server, <@${member.id}>! Make sure to check out <#757221255198802051> and <#757221255198802051>!`);
const serverCount = member.guild.memberCount;
member.guild.channels.cache.find(ch => ch.name.startsWith("Server Count: ")).setName(`Server Count: ${serverCount}`);
});