为什么我的 Minecraft 自定义聊天命令不起作用?

问题描述 投票:0回答:1

我的 Minecraft 自定义聊天命令不起作用。加载世界时出现错误。

我的代码:

import { world } from '@minecraft/server';
world.beforeEvents.chatSend.subscribe((eventData) => {
    const player = eventData.sender;
    switch (eventData.message) {
        case '!creative':
            eventData.cancel = true;
            player.runCommandAsync('gamemode c');
            break;
        case '!survival':
            eventData.cancel = true;
            player.runCommandAsync('gamemode s');
            break;
        default: break;
    }
});

加载世界时出现此错误消息:

[Scripting][error]-Plugin [Custom Commands - 1.0.0] - [index.js] ran with error: [TypeError: cannot read property 'subscribe' of undefined    at <anonymous> (index.js:3)]

有谁知道如何解决这个问题,因为网上没有太多可用的文档?

我尝试创建一个脚本,以便当我将

!creative
发送到聊天中时,它会将我的游戏模式更改为创意(
!survival
反之亦然)

我希望一切都会正常工作,因为我找到了多个教程,甚至尝试只是复制粘贴代码,但实际发生的是我在上面收到一条错误消息。

我使用的Minecraft版本是基岩版Release 1.20.40

javascript typeerror minecraft
1个回答
0
投票

确保在行为包的 manifest.json 文件中,依赖项中列出了“@minecraft/server”模块,并且还列出了正确的版本。

© www.soinside.com 2019 - 2024. All rights reserved.