How does bulkDelete work?(批量删除如何工作?)
问题描述
我尝试使用 bulkDelete
让我的机器人删除它的消息,但我收到此错误:
I tried using bulkDelete
to make my bot delete its message but I get this error:
(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还是其他什么?
What does the bulkDelete need? Is it the message id or something else?
我不知道我这样做是否正确(显然我不是),因为我开始编码时对 javascript 或任何相关知识的了解为零.
I have no idea if I doing this right (obviously I am not) since I started coding with zero knowledge of javascript or anything related.
推荐答案
从频道中删除 x
消息的最简单方法是提供 2 - 100
的整数作为 <TextChannel>.bulkDelete 的参数
方法.
The easiest way to delete x
messages from a channel is to provide an integer from 2 - 100
as parameters to the <TextChannel>.bulkDelete
method.
例子:
message.channel.bulkDelete(100).then(() => {
message.channel.send("Deleted 100 messages.").then(msg => msg.delete(3000));
});
这篇关于批量删除如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:批量删除如何工作?
- 400或500级别的HTTP响应 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07