Send a message to my private channel on join amp; leave(在加入时向我的私人频道发送消息 amp;离开)
问题描述
嘿嘿,
我希望我的机器人在加入时向我的私人不和谐服务器发送嵌入消息 &离开服务器.但问题是它不会在任何地方发送任何东西.我的代码如下所示:
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)
}
推荐答案
您的代码在加入服务器后未激活.为此,您有一个不错的活动(名称具有误导性)guildCreate - 它是每当客户加入公会时发出.
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);
});
离开公会也一样,使用 guildDelete 事件.
Same works for leaving the guild, use guildDelete event.
这篇关于在加入时向我的私人频道发送消息 &离开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在加入时向我的私人频道发送消息 &离开
基础教程推荐
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
