所以我试图让我的广播命令在一段时间后自动删除广播。我为之构建EBS机器人的人希望它在30分钟后自动删除。
我们让它像他想要的那样发送到所有的文本频道,但试图让它自动删除会触发以下错误:
(node:23) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied options is not an object.这是我的broadcast.js文件:
broadcast.js
const Commando = require('discord.js-commando');
const prefix = (process.env.BOT_PREFIX);
require('dotenv').config();
module.exports = class BroadcastCommand extends Commando.Command {
constructor(client) {
super(client, {
name: 'broadcast',
aliases: [
'ebcast',
'bcast',
'bc',
'ebc'
],
group: 'ebs',
memberName: 'broadcast',
userPermissions: [
'MANAGE_MESSAGES',
'MANAGE_CHANNELS'
],
description: 'Send an Emergency Broadcast to all text channels in the guild',
examples: [
`Usage: ${prefix}bc <message.content>`,
`Details: '<>' flags indicate a required field. '[]' flags indicates an optional field.`,
`Note: Do not include the '<>' or '[]' flags in the command.`
],
args: [
{
key: 'text',
prompt: 'What would you like the bot to announce?',
type: 'string',
},
],
})
};
run(msg, { text }) {
msg.guild.channels.cache
.filter(channel => channel.type === 'text')
.forEach((textChannel) => {
textChannel.send(text, { tts: true }).then(sentMessage => {
sentMessage.delete(108000000).cache(console.error);
});
})
}
};我们想知道如何将其设置为30分钟后自动删除消息。
我使用了这篇文章中的一个例子来自动删除代码,这显然对我不起作用:
Making a bot delete its own message after a timeout
帮助我将其发送到所有渠道的帖子来自:
Discord.js Commando Broadcast All command error
我假设是sentMessage标志出错了,但我可能错了。
任何帮助都将不胜感激。
该机器人是用discord.js-commando构建的,使用node.js ^12.16.4和discord.js ^12.0.1。它运行在discord.js-commando的discordjs/Commando主分支上
-编辑
感谢T. Dirk提供的解决这个问题的答案。
如果任何人想要使用固定的代码做任何事情,它是:
broadcast.js
const Commando = require('discord.js-commando');
const prefix = (process.env.BOT_PREFIX);
require('dotenv').config();
module.exports = class BroadcastCommand extends Commando.Command {
constructor(client) {
super(client, {
name: 'broadcast',
aliases: [
'ebcast',
'bcast',
'bc',
'ebc'
],
group: 'ebs',
memberName: 'broadcast',
userPermissions: [
'MANAGE_MESSAGES',
'MANAGE_CHANNELS'
],
description: 'Send an Emergency Broadcast to all text channels in the guild',
examples: [
`Usage: ${prefix}bc <message.content>`,
`Details: '<>' flags indicate a required field. '[]' flags indicates an optional field.`,
`Note: Do not include the '<>' or '[]' flags in the command.`
],
args: [
{
key: 'text',
prompt: 'What would you like the bot to announce?',
type: 'string',
},
],
})
};
run(msg, { text }) {
msg.guild.channels.cache
.filter(channel => channel.type === 'text')
.forEach((textChannel) => {
textChannel.send(text, { tts: true }).then(sentMessage => {
sentMessage.delete({ timeout: 108000000 }).catch(console.error);
});
})
};
};发布于 2020-10-02 17:02:33
您找到并使用的自动删除代码是基于Discord v11的。在这个版本中,Message.delete函数只需要一个数字作为参数来设置删除超时。
由于您使用的是不一致的JS v12,因此Message.delete代码稍有更改。它不接受数字作为参数,而是接受一个options对象。此options对象可以有两个属性:timeout和reason。因此,要解决这个问题,只需更改.delete参数,如下所示:
// Note that in your code you have .cache after the delete
// but I'm guessing you meant .catch to catch errors
sentMessage.delete({timeout: 108000000}).catch(console.error);https://stackoverflow.com/questions/64164610
复制相似问题