为 discord.js v12 切换问候命令

时间:2021-06-27 04:34:28

标签: discord.js

我制作了一个代码,用于在特定频道中迎接新成员,但我想切换它。 如果工作人员使用 !greet #channel,则将在 #channel 中启用问候消息。如果他们使用 !greet,它会禁用服务器的问候消息。

GuildMemberAdd 活动

client.on('guildMemberAdd', member =>{
    const channel = member.guild.channels.cache.find(ch => ch.name == 'welcome');
    if(!channel) return;
    channel.send(`Welcome to **${member.guild.name}**, ${member}!`)
    .then(message =>{
        message.delete({ timeout: 5000 })
    })
    .catch(console.error);
}); 

更多信息

我只是想让它成为一个切换命令,但我不知道该怎么做。我很高兴早日得到答复。

1 个答案:

答案 0 :(得分:2)

因此要切换哪个频道将发送欢迎消息,您需要将频道 ID 存储在数据库等某个地方,或者通过集合 .set 将其与公会附加。之后,在您的活动中发送消息之前,如果公会 ID 已经设置了欢迎频道,您将从公会 ID 中获取信息,因此将消息发送到该频道,否则什么都不做