在加入&上向我的私人频道发送消息离开 [英] Send a message to my private channel on join & leave
本文介绍了在加入&上向我的私人频道发送消息离开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Heyo,
我希望我的机器人在加入&离开服务器.但是问题在于它不会在任何地方发送任何东西.我的代码如下:
I want my bot to send a embed message to my private discord server when it joins & leaves a server. But the problem is that it does not send anything anywhere. My code looks like this:
exports.run = async (client, guild) => {
if(!guild.available) return
if(!guild.owner && guild.ownerID) await guild.members.fetch(guild.ownerID);
if(!channel) return;
const embed = new MessageEmbed()
.setTitle(`Bot joined a server`)
.setDescription(`${guild.name}`)
.setColor(0x9590EE)
.setThumbnail(guild.iconURL())
.addField(`Owner", "${guild.owner.user.tag}`)
.addField(`Member Count", "${guild.memberCount}`)
.setFooter(`${guild.id}`)
client.channels.cache.get('ID').send(embed)
}
推荐答案
您的代码在加入服务器后不会激活.为此,您有一个不错的活动(名称具有误导性)
Your code doesn't activate upon joining the server. For that you have a nice event (that has a misleading name) guildCreate
- it is emitted whenever the client joins a guild.
因此,您的代码应如下所示
So, your code should look something like this
client.on('guildCreate', async guild => {
let YourChannel = await client.channels.fetch('channelid');
const embed = new Discord.MessageEmbed()
.setTitle(`Bot joined a server`)
.setDescription(`${guild.name}`)
.setColor(0x9590EE)
.setThumbnail(guild.iconURL())
.addField(`Owner`, `${guild.owner.user.tag}`)
.addField(`Member Count`, `${guild.memberCount}`)
.setFooter(`${guild.id}`)
YourChannel.send(embed);
});
Same works for leaving the guild, use guildDelete
event.
这篇关于在加入&上向我的私人频道发送消息离开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文