猿问

广播所有命令不自动删除广播 - Discord.js-Commando

所以我试图让我的广播命令在一段时间后自动删除广播。我为其构建 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 分钟后自动删除消息。

我使用这篇文章中的一个示例来自动删除代码,这显然对我不起作用:

让机器人在超时后删除自己的消息

帮助我将其发送到所有频道的帖子来自:

Discord.js Commando Broadcast All 命令错误

我假设sentMessage标志是错误的,但我可能是错的。

任何帮助将非常感激。

该机器人内置discord.js-commando并使用node.js ^12.16.4discord.js ^12.0.1discordjs/Commando它从主分支运行 discord.js-commando


慕工程0101907
浏览 96回答 1
1回答

幕布斯7119047

您发现和使用的自动删除代码基于 Discord JS v11。在这个版本中,该Message.delete功能只需要一个数字作为参数来设置删除超时。由于您使用的是 Discord JS v12,因此Message.delete代码略有更改。它不采用数字作为参数,而是采用选项对象。这个选项对象可以有两个属性;timeout和reason。因此,解决问题所需要做的就是.delete像这样更改参数:// Note that in your code you have .cache after the delete// but I'm guessing you meant .catch to catch errorssentMessage.delete({timeout: 108000000}).catch(console.error);
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答