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.
这篇关于在加入时向我的私人频道发送消息 &离开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在加入时向我的私人频道发送消息 &离开
基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
