【问题标题】:invite Created event邀请 创建的活动
【发布时间】:2021-07-29 18:58:23
【问题描述】:

所以我正在制作一个具有自动日志记录功能的 Discord Bot,直到现在我都完成了大部分代码,其中包括设置 mod-log 通道的命令和事件代码,这里是命令:

let db = require(`quick.db`)

module.exports = {
  name: "modlog",
  aliases: ["modlogs", "log", "logs"],
  description: "Change the modlogs channel of the current server",
  permission: "MANAGE_CHANNELS",
  usage: "modlog #[channel_name]",
  run: async (client, message, args) => {
    if(!message.member.hasPermission(`MANAGE_CHANNELS`)) {
      return message.channel.send(`:x: You do not have permission to use this command!`)
    } else {
      let channel = message.mentions.channels.first();
      if(!channel) return message.channel.send(`:x: Please specify a channel to make it as the modlogs!`)
      await db.set(`modlog_${message.guild.id}`, channel)
      message.channel.send(`Set **${channel}** as the server's modlog channel!`)
    }
  }
}

还有inviteCreate 事件:

client.on("inviteCreate", async invite => {
  const log = client.channels.cache.get(`${`modlog_${message.guild.id}`}`)
  let inviteCreated = new Discord.MessageEmbed()
  log.send(`An invite has been created on this server!`)
})

问题在于,由于inviteCreate 事件只接受一个参数(我认为这就是它们的名称),即invite,因此没有message 参数,因此消息变得未定义,有没有人有解决方案? 谢谢!

【问题讨论】:

  • 好的,看起来您的上次编辑现在是一个完全不同的问题。如果对您有帮助,您应该在此处投票(并且两个答案都是您设法从邀请中获得公会 ID),并使用新的详细信息创建一个新问题。

标签: javascript discord discord.js


【解决方案1】:

在这种情况下,您不需要 message。请参阅documentation of invite

【讨论】:

  • 这里有一些不错的额外信息,@NullDev ;)
【解决方案2】:

Invites 也有一个guild 属性,这是邀请的公会,所以你可以使用它来代替message.guild

client.on('inviteCreate', async (invite) => {
  const log = client.channels.cache.get(`${`modlog_${invite.guild.id}`}`);
  let inviteCreated = new Discord.MessageEmbed();
  log.send(`An invite has been created on this server!`);
});

【讨论】:

  • 我已经检查过了,并且 “设法找到了解决方案” 在不知道那是什么的情况下并没有真正的帮助
  • 这应该是一个新问题,而不是一个编辑。最初的问题得到了回答,@NullDev 和我都回答了​​如何在 inviteCreate 事件中获取公会 ID。您上次的编辑与此无关。
  • 哦,好的,抱歉,我将创建一个新问题,谢谢你们!
  • 别担心,这不是什么大问题 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-25
相关资源
最近更新 更多