【发布时间】:2021-07-29 15:59:51
【问题描述】:
所以我尝试为我的不和谐机器人使用斜杠命令,我已经从旧机器人复制并更改了一些警告命令,其中警告命令在没有斜杠命令的情况下工作。
我的代码是
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 并阅读提及,我们将不胜感激。
【问题讨论】:
-
如何调用
callback函数? -
什么意思?
-
我的意思是,您使用
callback方法导出一个对象,然后在某处调用它,但您似乎没有传递正确的参数。 -
那我该如何解决呢?
-
我不知道。我已经问过您是如何使用
callback的,但您没有向我们展示任何内容。
标签: discord.js