gpt4 book ai didi

javascript - bulkDelete 如何工作?

转载 作者:行者123 更新时间:2023-11-30 11:44:07 24 4
gpt4 key购买 nike

我尝试使用 bulkDelete 让我的机器人删除它的消息,但我收到此错误:

(node:5724) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Bad Request
(node:5724) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是我的代码:

const Discord = require('discord.js');
const bot = new Discord.Client();
const config = require("./config.json");

bot.on('ready', () =>{
console.log('I am ready!');
});

//var cleanarr=[];

bot.on("message", message =>{
if (message.author.bot) return;
var cleanarr=[];
let command = message.content.split(" ")[0];
command = command.slice(config.prefix.length);

let args = message.content.split(" ").slice(1);
if (message.content == 'lol'){
message.channel.sendMessage('LUL');
cleanarr.unshift(`${message.channel.lastMessageID}`);
}
if (command == "clean") {
message.channel.sendMessage('Cleaning...');
message.channel.bulkDelete(cleanarr);
var cleanarr = [];

bulkDelete 需要什么?是消息 ID 还是其他?

我不知道我这样做是否正确(显然我不是),因为我开始编码时对 javascript 或任何相关知识都是零知识。

最佳答案

最简单的删除方法x来自 channel 的消息是提供来自 2 - 100 的整数作为 <TextChannel>.bulkDelete 的参数方法。

例子:

message.channel.bulkDelete(100).then(() => {
message.channel.send("Deleted 100 messages.").then(msg => msg.delete(3000));
});

关于javascript - bulkDelete 如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41574971/

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