gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:10:28 25 4
gpt4 key购买 nike

所以我试图让我的广播命令在设定的时间后自动删除广播。我为其构建 EBS 机器人的人希望它在 30 分钟后自动删除。

我们让它按照他的意愿发送到所有文本 channel ,但试图让它自动删除会触发以下错误:

(node:23) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied options is not an object.

这是我的 broadcast.js 文件:

广播.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

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

Discord.js Commando Broadcast All command error

我假设 sentMessage 标志出错了,但我可能错了。

如有任何帮助,我们将不胜感激。

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

---编辑---

感谢 T。 Dirk 解决这个问题的答案。

如果有人想使用固定代码做任何事情,这里是:

广播.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);
});
})
};
};

最佳答案

您找到并使用的自动删除代码基于 Discord JS v11。在此版本中,Message.delete函数只需要一个数字作为参数来设置删除超时。

由于您使用的是 Discord JS v12,因此 Message.delete代码略有改变。它不采用数字作为参数,而是采用选项对象。这个选项对象可以有两个属性; 超时原因。因此,解决问题所需要做的就是更改 .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);

关于javascript - 广播所有命令不自动删除广播 - Discord.js-Commando,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64164610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com