这是我的代码
bot.on("guildMemberRemove", async (member) => {
const tlog = await member.guild.fetchAuditLogs({
limit: 1,
type: "MEMBER_KICK",
});
const klog = tlog.entries.first();
const { executor, target } = klog;
const rs = tlog.entries.first().reason;
const emb = new Discord.MessageEmbed()
.setTitle("Új KICK!") //New Kick Title
.addField("Kickelt neve", target.user) //The kicked member name
.addField("Kickelő neve", executor) //The member who kicked the other member
.addField("Indok", rs) //Reason
.setTimestamp()
.setColor(15158332)
addToLog(emb);
})
addToLog 函数
const channell = "792743591017316413"; //Channel id
function addToLog(message){
const szoba = bot.channels.cache.get(channell); //szoba means room
return szoba.send(message);
};
我在更多网站上寻找解决方案,但我完全复制了代码,没有任何反应。
答案 0 :(得分:0)
如果您看一下 docs for TextChannel.send()。它返回一个承诺,您需要使用 await
或 .then()
来解决这个承诺。
答案 1 :(得分:0)
我将您的代码编辑为:
function addToLog(message, channel) {
return channel.send(message);
};
bot.on("guildMemberRemove", async (member) => {
const tlog = await member.guild.fetchAuditLogs({
limit: 1,
type: "MEMBER_KICK",
});
const klog = tlog.entries.first();
const { executor, target } = klog;
const rs = tlog.entries.first().reason;
const channell = "Your channel ID"; //Channel id
const szoba = bot.channels.cache.find(ch => ch.id === channell);
const emb = new Discord.MessageEmbed()
.setTitle("Új KICK!") //New Kick Title
.addField("Kickelt neve", target.user) //The kicked member name
.addField("Kickelő neve", executor) //The member who kicked the other
member
.addField("Indok", rs) //Reason
.setTimestamp()
.setColor(15158332)
addToLog(emb, szoba);
})
我使用了第二个参数 channel
,在本例中是您的 szoba
。因此,您在函数外部初始化了两个常量 channell
和 szoba
。然后您提供一条消息和您的常量 szoba
(这是您希望将日志发送到的频道)。在函数 addToLog()
中,您只需要将提供的消息发送到提供的频道 (szoba
)。