在加入时向我的私人频道发送消息 &离开

时间:2023-02-10
本文介绍了在加入时向我的私人频道发送消息 &离开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿嘿,

我希望我的机器人在加入时向我的私人不和谐服务器发送嵌入消息 &离开服务器.但问题是它不会在任何地方发送任何东西.我的代码如下所示:

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.

这篇关于在加入时向我的私人频道发送消息 &离开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:从客户端状态的成员计数中过滤掉机器人 下一篇:如何修复错误:Fontconfig 错误:无法加载默认配置文

相关文章

最新文章