无法读取未定义的属性“提及”,无法读取未定义的| Discord.js斜杠命令的属性“guild”

无法读取未定义的属性“提及”,无法读取未定义的| Discord.js斜杠命令的属性“guild”,discord.js,Discord.js,因此,我尝试为我的discord bot使用slash命令,我从旧bot复制并更改了一点warn命令,其中warn命令在没有slash命令的情况下工作 我的代码是 const { MessageEmbed } = require('discord.js') const mongo = require('../mongo') const warnSchema = require('../schemas/warn-schema') const Discord = require('discord.j

因此,我尝试为我的discord bot使用slash命令,我从旧bot复制并更改了一点warn命令,其中warn命令在没有slash命令的情况下工作

我的代码是

const { MessageEmbed } = require('discord.js')
const mongo = require('../mongo')
const warnSchema = require('../schemas/warn-schema')
const Discord = require('discord.js')

module.exports = {
  slash: 'both',
  testOnly: true,
  minArgs: 2,
  expectedArgs: '<mention> <reason>',
  description: "warns mentioned user",
  callback: async ({ message, args }) => {

const [mention, reason] = args

      const target = message.mentions.users.first()

 

    const guildId = message.guild.id
    const userId = target.id
    

    const warning = {
      author: message.member.user.tag,
      timestamp: new Date().getTime(),
      reason,
    }

const yerz = new MessageEmbed()
  .setTitle('yes')

    await mongo().then(async (mongoose) => {
      try {
        await warnSchema.findOneAndUpdate(
          {
            guildId,
            userId,
          },
          {
            guildId,
            $push: {
              warnings: warning,
            },
          },
          {
            upsert: true,
          }
        )
      } finally {
        mongoose.connection.close()
      }
    })

    return yerz
  },
}

如果有人知道我如何让机器人找到guid id并阅读提及的内容,将不胜感激。

我认为问题出在你的JS代码中:

callback: async ({ message, args }) => {
应该是:

callback: async ({ message, args }) {
没有=>因为在这种情况下=>和{}是互斥的

如果这还不能解决问题,可能是因为:

const [mention, reason] = args

你能告诉我们args是什么吗?我猜它是一个对象,但我不确定。

如何调用回调函数?你是什么意思?我的意思是,你用回调方法导出一个对象,然后在某个地方调用它,似乎没有传递正确的参数。那么我该如何修复它?我不知道。我已经问过你是如何使用这个回调的,但是你没有给我们看任何东西。