node.js - -UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message-
问题描述
我对 discord.js 编程很陌生,所以请温柔一点。
这是我的机器人应该负责删除消息的代码。
有时在清除消息时,我会从问题的标题中得到一个错误。
我应该在某处使用 catch 块,如果是,在哪里?
bot.on('message', function(message){
if(input.startsWith(prefix + 'CLR')){
message.delete();
var clrcommand = input.toString().split(' ');
if(!clrcommand[1]){
message.channel.send({embed:{
title:'<clr ?',
description:'Error! Please specify the number of messages to clear e.g. <clr 10',
color:0x2471A3
}})
return;
}
if(sender.id === 'xxxxxxxxxxxxxxxxxx'){
nmb=Number(clrcommand[1]);
message.channel.bulkDelete(nmb);
}
else{
message.channel.send({embed:{
title:'<clr '+clrcommand[1],
description:'You do not have permissions to request the deletion of messages on this server!',
color:0x2471A3
}})
return;
}
}
});
解决方案
通过删除message.delete();
线,我设法解决了我的问题。感谢@Cannicide 的帮助。
以下是修改后的代码,添加了一些内容。也许它可以帮助某人。干杯。:)
bot.on('message', function(message){
if(input.startsWith(prefix + 'CLR')){
var clrcommand = input.toString().split(' ');
if(!clrcommand[1]){
message.channel.send({embed:{
title:'<clr ?',
description:'Error! Please specify the number of messages to clear e.g. <clr 10',
color:0x2471A3
}})
return;
}
if((clrcommand[1] < 1) || (clrcommand[1] > 99)){
message.channel.send({embed:{
description:'You need to enter a number between 1 and 99!',
color:0x2471A3
}});
}
if(sender.id === 'xxxxxxxxxxxxxxxxxx'){
nmb=Number(clrcommand[1]);
message.channel.bulkDelete(nmb);
}
else{
message.channel.send({embed:{
title:'<clr '+clrcommand[1],
description:'You do not have permissions to request the deletion of messages on this server!',
color:0x2471A3
}})
return;
}
}
});
推荐阅读
- javascript - React - 如何强制重新加载类组件?
- react-native - react-native-community/asyncStorage removeItem 导致程序行为异常
- python - Django - 按字段比较用户对象
- swiftui - 如何从 SwiftUI 中的 apns 点击导航到某些视图?
- python - SkImage 中 cv2.INTER_AREA 的等价物
- node.js - 为节点 js 中的每个用户运行计划功能
- javascript - 通过 selft 内的 settimeout 参数重复函数
- postman - 如何在发布请求中创建数据时传递 API 密钥
- loadrunner - UFT 与 LoadRunner 的集成
- reactjs - react-beautiful-dnd - 如果存在超过 4 个列表,则在下一行添加列表