所以我试图让我的广播命令在设定的时间后自动删除广播。我为其构建 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 分钟后自动删除消息。
我使用了这篇文章中的一个示例来自动删除代码,这显然对我不起作用:
帮助我将其发送到所有频道的帖子来自:
我假设sentMessage
标志是错误的,但我可能错了。
任何帮助将非常感激。
该机器人内置discord.js-commando
并使用node.js ^12.16.4
和discord.js ^12.0.1
。它从 discordjs/Commando
主分支运行discord.js-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);
});
})
};
};