簡體   English   中英

無法讀取“lang”的屬性

[英]Property of 'lang' cannot be read

我正在嘗試制作一個文本到語音的不和諧機器人。 我更像是一個編碼新手,所以我不完全明白這里發生了什么。 我編寫的代碼用於執行一個名為“lang”的簡單命令,該命令將切換 TTS 語言。

const prefix = process.env.prefix;
const languages = require('../../data/languages.json');

module.exports = {
  name: 'lang',
  description: 'Change the TTS language.',
  emoji: ':map:',
  execute(message, options) {
    let [newLang] = options.args;
    const { ttsPlayer } = message.guild;

    if (!newLang) {
      message.reply(`to set-up the TTS language, run: **${prefix}lang <lang_code>**
      To see a list of the available lang codes, run: **${prefix}langs**.
      The current language is set to: **${languages[ttsPlayer.lang]}**.`);
      return;
    }

    newLang = newLang.toString().toLowerCase();

    ttsPlayer.setLang(newLang)
      .then((setLang) => {
        message.reply(`language has been set to **${setLang}**.`);
      })
      .catch((error) => {
        message.reply(error);
      });
  }
}

我得到的錯誤是:

2020-03-04T22:04:23.278707+00:00 app[worker.1]: [31m(10:04:23 PM) - [ERROR] - TypeError: Cannot read property 'lang' of null
2020-03-04T22:04:23.278709+00:00 app[worker.1]:     at Object.execute (/app/src/commands/lang.js:15:63)
2020-03-04T22:04:23.278710+00:00 app[worker.1]:     at executeCommand (/app/src/common/utils.js:46:13)
2020-03-04T22:04:23.278710+00:00 app[worker.1]:     at Object.handleMessage (/app/src/events/handlers/app.js:50:3)
2020-03-04T22:04:23.278711+00:00 app[worker.1]:     at Client.<anonymous> (/app/index.js:33:55)
2020-03-04T22:04:23.278711+00:00 app[worker.1]:     at Client.emit (events.js:323:22)
2020-03-04T22:04:23.278712+00:00 app[worker.1]:     at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
2020-03-04T22:04:23.278713+00:00 app[worker.1]:     at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
2020-03-04T22:04:23.278715+00:00 app[worker.1]:     at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
2020-03-04T22:04:23.278715+00:00 app[worker.1]:     at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:435:22)
2020-03-04T22:04:23.278715+00:00 app[worker.1]:     at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)

有人可以幫我嗎?

我想問題是變量 ttsPlayer 為空。 請檢查 message.guild 中是否存在此類屬性?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM