So I'm trying to get my broadcast command to auto delete the broadcasts after a set amount of time. The person I built the EBS bot for wants it to auto delete after 30 minutes.
We got it to send to all text channels as he wanted but trying to make it auto delete triggers the following error:
(node:23) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied options is not an object.
Here is my broadcast.js
file:
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);
});
})
}
};
We would like to know how to set it to auto delete messages after 30 minutes.
I used an example from this post for the code to auto delete which apparently isn't working for me:
Making a bot delete its own message after a timeout
And the post that helped me get it to send to all channels is from:
Discord.js Commando Broadcast All command error
I'm assuming the sentMessage
flag is what's erroring out, but I may be wrong.
Any help would be much appreciated.
The bot is built in discord.js-commando
and uses node.js ^12.16.4
and discord.js ^12.0.1
. It runs off of the discordjs/Commando
master branch for discord.js-commando
---EDIT---
Thanks go to T. Dirk
for the answer that fixed this.
If anyone wants to use the fixed code for anything, here it is:
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);
});
})
};
};