首先要注意一点,这是一个打字稿文件。我在执行清除/清除命令时遇到问题。此命令适用于 discord v11,但在 v12 上存在问题。我看到的问题是 'TextChannel | 类型不存在 bulkDelete DM频道 | 新闻频道'我不知道哪里出了问题。我不只是在寻找一个修复,解释为什么它不起作用将不胜感激。提前致谢!
import * as Discord from "discord.js";
import { IBotCommand } from "../api";
export default class purge implements IBotCommand {
private readonly _command = "purge"
help(): string {
return "(Admin only) Deletes the desired numbers of messages.";
}
isThisCommand(command: string): boolean {
return command === this._command;
}
async runCommand(args: string[], msgObject: Discord.Message, client: Discord.Client): Promise<void> {
//converts args into a number
let numberOfMessagesToDelete = parseInt(args[0],10);
//make sure number is interger
numberOfMessagesToDelete = Math.round(numberOfMessagesToDelete + 1);
//clean up msgs
msgObject.delete()
.catch(console.error);
if(!msgObject.member.hasPermission("KICK_MEMBERS")) {
msgObject.channel.send(`${msgObject.author.username}, AH! AH! AH! You didn't say the magic word!`)
.then(msg => {
(msg as Discord.Message).delete({timeout:10000})
});
return;
}
//message amount
if(!args[0]){
msgObject.channel.send(`Improper format! Proper format is "-purge 12"`)
.then(msg => {
(msg as Discord.Message).delete({timeout:10000})
.catch(console.error);
});
return;
}
//verifies args[0] actual number
if(isNaN(numberOfMessagesToDelete)){
msgObject.channel.send(`Improper number! Pick a number between 1 and 99!`)
.then(msg => {
(msg as Discord.Message).delete({timeout:10000})
.catch(console.error);
});
return;
}
//delete desired number of messages
let auditLog = client.channels.cache.find(channel => channel.id === "623217994742497290") as Discord.TextChannel;
const bdEmbed = new Discord.MessageEmbed()
.setTitle(`**Message Purge**`)
.setDescription(`${numberOfMessagesToDelete} messages were deleted in ${msgObject.channel.toString()} by ${msgObject.author.username}`)
.setTimestamp()
.setColor([38,92,216])
.setThumbnail(msgObject.author.displayAvatarURL())
msgObject.channel.bulkDelete(numberOfMessagesToDelete)
auditLog.send(bdEmbed)
.catch(console.error);
}
}