亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

廣播所有命令不自動刪除廣播 - Discord.js-Commando

廣播所有命令不自動刪除廣播 - Discord.js-Commando

慕工程0101907 2023-04-14 15:10:29
所以我試圖讓我的廣播命令在一段時間后自動刪除廣播。我為其構建 EBS 機器人的人希望它在 30 分鐘后自動刪除。我們讓它按照他的意愿發送到所有文本頻道,但試圖讓它自動刪除會觸發以下錯誤:(node:23) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied options is not an object.這是我的broadcast.js文件:broadcast.jsconst 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.4和discord.js ^12.0.1。discordjs/Commando它從主分支運行 discord.js-commando
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

您發現和使用的自動刪除代碼基于 Discord JS v11。在這個版本中,該Message.delete功能只需要一個數字作為參數來設置刪除超時。

由于您使用的是 Discord JS v12,因此Message.delete代碼略有更改。它不采用數字作為參數,而是采用選項對象。這個選項對象可以有兩個屬性;timeoutreason。因此,解決問題所需要做的就是.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);


查看完整回答
反對 回復 2023-04-14
  • 1 回答
  • 0 關注
  • 110 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號