#Define "msg" [Uhm]

1 messages · Page 1 of 1 (latest)

plush crystal
#

If I run this script it says "msg" isn't defined but Idk what that means:

// Script example for ScriptAPI
// Author: Smell of curry <https://github.com/smell-of-curry>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Player, world } from "@minecraft/server";
const rank_prefix = "rank:";
const default_rank = "Member";
function getRanks(player) {
  const ranks = player
    .getTags()
    .map((v) => {
      if (!v.startsWith(rank_prefix)) return null;
      return v.substring(rank_prefix.length);
    })
    .filter((x) => x);
  return ranks.length == 0 ? [default_rank] : ranks;
}
world.events.beforeChat.subscribe((data) => {
  data.sendToTargets = true;
  data.targets = [];
  const ranks = getRanks(data.sender).join("§r");
  if (msg.startsWith("!")) return;
  const message = data.message;
  world.say(`§r${ranks}§r§7: ${data.sender.name} >§r ${message}`);
});
#

Should I replace msg.startsWith with message.startsWith?

#

Please help me with this

#

_

#

_

novel cargo
# plush crystal Should I replace msg.startsWith with message.startsWith?
// Script example for ScriptAPI
// Author: Smell of curry <https://github.com/smell-of-curry>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Player, world } from "@minecraft/server";
const rank_prefix = "rank:";
const default_rank = "Member";
function getRanks(player) {
  const ranks = player
    .getTags()
    .map((v) => {
      if (!v.startsWith(rank_prefix)) return null;
      return v.substring(rank_prefix.length);
    })
    .filter((x) => x);
  return ranks.length == 0 ? [default_rank] : ranks;
}
world.events.beforeChat.subscribe((data) => {
  const message = data.message;
  if (message.startsWith("!")) return;
  data.sendToTargets = true;
  data.targets = [];
  const ranks = getRanks(data.sender).join("§r");
  world.say(`§r${ranks}§r§7: ${data.sender.name} >§r ${message}`);
});
glass belfryBOT
#
Debug Result

There are errors in this [code](#1086762578467881110 message):

<repl>.js:21:8 - error TS2339: Property 'targets' does not exist on type 'BeforeChatEvent'.

21   data.targets = [];
          ~~~~~~~
<repl>.js:23:9 - error TS2339: Property 'say' does not exist on type 'World'.

23   world.say(`§r${ranks}§r§7: ${data.sender.name} >§r ${message}`);
           ~~~

novel cargo
#

wtf are u even trying to do with the targets thing

#

also say is no longer a thing, use sendMessage instead

plush crystal
#

Define "msg" [Uhm]

glass belfryBOT
#
No Errors

No errors in [code](#1086762578467881110 message)