我正在尝试做到这一点,因此,当我的机器人被添加到另一台服务器时,它将发送一个嵌入消息,告知它现在有多少台服务器,行会名称以及行会所有者。我还试图进行另一个嵌入,以便它告诉我何时离开服务器,并告诉我何时首先加入服务器,然后何时移除服务器,以及行会名称和行会所有者。我使用discord.js。有人可以帮忙吗?这是我当前的脚本:
bot.on("guildCreate", guild => {
const joinserverembed = new Discord.MessageEmbed()
.setTitle("Joined a server!")
.addField("Guild name:", `${guild.name}`)
.addField("Time of join:", `${Discord.Guild.createdTimestamp()}`)
.setColor("GREEN")
.setThumbnail(guild.displayAvatarURL())
if (guilds.channel.id = 740121026683207760) {
channel.send(joinserverembed)
}
guild.channel.send("Thank you for inviting Ultra Bot Premium! Please use up!introduction and up!help for the new perks and more!")
})
bot.on("guildDelete", guild => {
const leftserverembed = new Discord.MessageEmbed()
.setTitle("Left a server!")
.addField("Guild name:", `${guild.name}`)
.addField("Time of removal:", `${createdTimestamp()}`)
.setColor("RED")
.setThumbnail(guild.displayAvatarURL())
if (guilds.channel.id = 740121026683207760) {
channel.send(leftserverembed)
}
})
答案 0 :(得分:2)
我已通过以下代码为您解决了您的第一个问题。
guild.channel.send()
,在这种情况下,guild
代表Discord.Guild
,但是您正在使用它,就像它代表Message
的实例一样,它并不。您可以使用guild.channels.cache.find(x => x.name == 'general').send("Thanks for inviting me to this server¬!")
将消息发送到该服务器中名为general
的频道。
bot.on("guildCreate", (guild) => {
const joinserverembed = new Discord.MessageEmbed()
.setTitle("Joined a server!")
.addField("Guild name:", guild.name)
.addField("Time of join:", Date.now())
.setColor("GREEN")
.setThumbnail(guild.iconURL({ dynamic: true }));
bot.channels.cache.get("740121026683207760").send(joinserverembed);
guild.channels.cache
.filter((c) => c.type === "text")
.random()
.send(
"Thank you for inviting Ultra Bot Premium! Please use up!introduction and up!help for the new perks and more!"
);
});
我过滤了行会中的频道,确保它们不是类别或语音频道,然后将欢迎消息发送给随机频道。
对于第二个查询,您需要使用数据库,存储添加日期的Date.now时间戳记,然后一旦机器人离开行会,它就必须获取值并显示其时间。我没有为您完成此操作,但已修复您的代码:
bot.on("guildDelete", (guild) => {
const leftserverembed = new Discord.MessageEmbed()
.setTitle("Left a server!")
.addField("Guild name:", guild.name)
.addField("Time of removal:", Date.now())
.setColor("RED")
.setThumbnail(guild.iconURL({ dynamic: true }));
bot.channels.cache.get("740121026683207760").send(leftserverembed);
});