const levenshtein = require("fast-levenshtein");

exports.run = async (client, msg) => {
  if (msg.author.bot) return;
  if (client.config.selfbot && msg.author.id !== client.user.id) return;

  const conf = client.configuration.get(msg.guild);
  const prefixLength = client.funcs.parseCommand(client, msg, true);
  if (!prefixLength) return;
  const command = client.funcs.parseCommand(client, msg);
  if (command.length && !(client.commands.has(command) || client.aliases.has(command))) {
    const distances = [];
    client.commands.filter(c => c.conf.permLevel <= msg.member.permLevel).forEach((val, cmd) => distances.push({
      dist: levenshtein.get(cmd, command),
      cmd,
    }));
    distances.sort((a, b) => (a.score < b.score ? 1 : -1));
    if (distances[0] && distances[0].dist <= 1) {
      const message = await msg.channel.send(`|\`❔\`| Did you mean \`${conf.prefix + distances[0].cmd}\`?`);
      setTimeout(() => { if (message.deletable) message.delete(); }, 10000);
    }
  }
};

exports.conf = {
  enabled: true,
  requiredModules: ["fast-levenshtein"],
};

exports.help = {
  name: "didyoumean",
  type: "monitors",
  description: "Helps users that type in commands incorrectly.",
};

@@ -1,51 +1,348 @@
-const levenshtein = require(%22fast-levenshtein%22)
+/* eslint-disable no-use-before-define, no-restricted-syntax, consistent-return, guard-for-in */%0A%0Aconst levenshtein = require(%22fast-levenshtein%22);%0A%0Aexports.minDist = null;%0A%0Aexports.init = (client) =%3E %7B%0A  this.minDist = client.config.minDist && Number.isInteger(client.config.minDist) && client.config.minDist %3E= 1 ? client.config.minDist : 1;%0A%7D
 ;%0A%0Ae
@@ -403,42 +403,26 @@
 .bot
-) return;%0A  if
+ %7C%7C
  (
+!
 client.
-config.self
+user.
 bot 
@@ -457,16 +457,17 @@
 user.id)
+)
  return;
@@ -480,88 +480,42 @@
 nst 
-conf = client.configuration.get(msg.guild);%0A  const prefixLength = client.funcs.
+%7B prefixLength, command %7D = await 
 pars
@@ -538,14 +538,8 @@
  msg
-, true
 );%0A 
@@ -572,89 +572,42 @@
 ;%0A  
-const 
+if (!
 command
- = client.funcs.parseCommand(client, msg);%0A  if (command.length && !
+.length) return;%0A  if 
 (cli
@@ -663,22 +663,26 @@
 ommand))
-) %7B%0A  
+ return;%0A%0A
   const 
@@ -701,103 +701,54 @@
 %5B%5D;%0A
-    client.commands.filter(c =%3E c.conf.permLevel %3C= msg.member.permLevel).forEach((val, cmd) =%3E
+%0A  for (const cmd of msg.usableCommands) %7B%0A   
  dis
@@ -792,16 +792,19 @@
 .get(cmd
+%5B0%5D
 , comman
@@ -824,21 +824,61 @@
 ,%0A    %7D)
-)
 ;%0A  
+%7D%0A%0A  if (distances.length === 0) return;%0A
   distan
@@ -900,43 +900,29 @@
  =%3E 
-(
 a.
-score %3C b.score ? 1 : -1));%0A 
+dist - b.dist);%0A%0A
   
- 
 if (
@@ -933,16 +933,25 @@
 ances%5B0%5D
+.dist %3E 0
  && dist
@@ -971,52 +971,38 @@
  %3C= 
-1) %7B%0A      const message = await msg.channel
+this.minDist) %7B%0A    return msg
 .sen
@@ -1029,20 +1029,33 @@
 ean %5C%60$%7B
-conf
+msg.guildSettings
 .prefix 
@@ -1076,98 +1076,80 @@
 .cmd
+%5B0%5D
 %7D%5C%60?%60)
-;%0A      setTimeout(() =%3E %7B if (message.deletable) message.delete(); %7D, 10000
+.catch((err) =%3E %7B%0A      client.console.log(err, %22error%22
 );%0A    %7D
 %0A  %7D
@@ -1144,16 +1144,18 @@
 );%0A    %7D
+);
 %0A  %7D%0A%7D;%0A
@@ -1357,12 +1357,502 @@
 ectly.%22,%0A%7D;%0A
+%0Aconst parseCommand = async (client, msg) =%3E %7B%0A  const prefix = client.funcs.getPrefix(client, msg);%0A  if (!prefix) return false;%0A  const prefixLength = getLength(client, msg, prefix);%0A  return %7B%0A    command: msg.content.slice(prefixLength).trim().split(%22 %22)%5B0%5D.toLowerCase(),%0A    prefixLength,%0A  %7D;%0A%7D;%0A%0Aconst getLength = (client, msg, prefix) =%3E %7B%0A  if (client.config.prefixMention === prefix) return prefix.exec(msg.content)%5B0%5D.length + 1;%0A  return prefix.exec(msg.content)%5B0%5D.length;%0A%7D;%0A

Update didyoumean for Komada 0.20.x