Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Discord.js疑难解答-特定bot命令的奇怪行为_Javascript_Node.js_Discord.js - Fatal编程技术网

Javascript Discord.js疑难解答-特定bot命令的奇怪行为

Javascript Discord.js疑难解答-特定bot命令的奇怪行为,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,我正在使用Node.js(使用API)创建Discord bot,在运行我的一个命令($$server)时遇到了一些奇怪的行为。问题是,我正在为bot使用我定制的翻译引擎(它实际上是bot本身的一部分),而这个问题似乎源于完全的胡说八道。首先,为了简单起见,我不会包含所有代码。如果您想从整个代码中了解bot的实际工作方式,请转到,我已经上传了最新的更新。为了节省一些空间,我去掉了未使用和不重要的代码 现在,问题是:相同的代码(不包括我的调试代码)对不同的不协调语音通道区域的工作方式不同。除了四个

我正在使用Node.js(使用API)创建Discord bot,在运行我的一个命令(
$$server
)时遇到了一些奇怪的行为。问题是,我正在为bot使用我定制的翻译引擎(它实际上是bot本身的一部分),而这个问题似乎源于完全的胡说八道。首先,为了简单起见,我不会包含所有代码。如果您想从整个代码中了解bot的实际工作方式,请转到,我已经上传了最新的更新。为了节省一些空间,我去掉了未使用和不重要的代码

现在,问题是:相同的代码(不包括我的调试代码)对不同的不协调语音通道区域的工作方式不同。除了四个美国地区(美国西部、东部、中部、南部),所有地区的工作方式几乎相同。我已经查看了区域ID,它们被正确解释了。问题是,当我设置一个美国地区时,它能找到的第一个翻译(嵌入页脚)突然停止工作。我还尝试设置调试代码(simple
console.log()
function),事情就是这样。在
server.js
中,它实际上只是打印出实际的不和谐语音区域。根本不影响功能。然而,在
functions.js
中,调试代码的存在(只是打印出
regex
输出的内容,没有其他内容)使得代码突然停止在有问题的行上工作(通过
functions.js
中的注释突出显示),而不仅仅是在设置了美国地区的情况下

这是
functions.js
的内容(去掉了不必要的代码):

/*****************************************
*小丑不和谐机器人
*CZghost/Polda1822019年制造
*αv0.0.1
* 
*文件:functions.js
*****************************************/
const{Permissions}=require(“discord.js”);
const locales=require(“./locales.js”);
const literals=require(“./literals.js”);
常量颜色=需要(“颜色”);
module.exports={
// ...
//解析区域设置字符串
resolveLocale:(localeString,localeCode)=>{
localeString=localeString.toLowerCase().trim();
//除#locale{}之外的任何内容都不是区域设置字符串
如果(!localeString.startsWith('#locale{')| |!localeString.endsWith('}'))返回localeString;
if(!literals.locales.includes(localeCode))返回null;//无法识别区域设置代码
if(Object.prototype.hasOwnProperty.call(literals.locales\u map,localeCode))
localeCode=literals.locales\u map[localeCode];//未遇到国家/地区代码,映射到默认国家/地区
//检查区域设置字符串是否存在匹配项
const regex=/#locale\{([a-zA-Z0-9:::]+)\}/g;

//调试好的,原来我没想到在区域代码中会有连字符,我忘记了。没有在
正则表达式中包含连字符:D是的,这太愚蠢了


因此,唯一的解决方案是在
regex
表达式中包含连字符。

好的,结果我没想到在区域设置代码中包含连字符,我忘记了。没有在
regex
表达式中包含连字符:D是的,这很愚蠢

因此,唯一的解决方案是在
regex
表达式中包含连字符

C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot>node .     
Template locale file found, ignoring
.----------------------------.
|          Commands          |
|----------------------------|
|  Command  |  Load status   |
|-----------|----------------|
| ping.js   | Okay |
| server.js | Okay |
| whois.js  | Okay |
'----------------------------'
.---------------------------------.
|             Events              |
|---------------------------------|
|     Event      |  Load status   |
|----------------|----------------|
| error.js       | Okay |
| guildCreate.js | Okay |
| guildDelete.js | Okay |
| message.js     | Okay |
| ready.js       | Okay |
'---------------------------------'
Bot logged in as `Joker#0156`, user ID: `484988029841440808`
`us-central`
[
  '#locale{commands:serverinfo:query:footer}',
  'commands:serverinfo:query:footer',
  index: 0,
  input: '#locale{commands:serverinfo:query:footer}',
  groups: undefined
]
(node:36692) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of null
    at resolveLocale (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\functions.js:196:47)
    at Object.run (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\commands\info\server.js:35:24)
    at run (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\events\message.js:59:30)
    at Client.emit (events.js:223:5)
    at MessageCreateHandler.handle (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:223:5)
(node:36692) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:36692) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
`sydney`
[
  '#locale{commands:serverinfo:query:footer}',
  'commands:serverinfo:query:footer',
  index: 0,
  input: '#locale{commands:serverinfo:query:footer}',
  groups: undefined
]
(node:36692) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of null
    at resolveLocale (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\functions.js:196:47)
    at Object.run (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\commands\info\server.js:35:24)
    at run (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\events\message.js:59:30)
    at Client.emit (events.js:223:5)
    at MessageCreateHandler.handle (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:223:5)
(node:36692) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
^C
C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot>node .
Template locale file found, ignoring
.----------------------------.
|          Commands          |
|----------------------------|
|  Command  |  Load status   |
|-----------|----------------|
| ping.js   | Okay |
| server.js | Okay |
| whois.js  | Okay |
'----------------------------'
.---------------------------------.
|             Events              |
|---------------------------------|
|     Event      |  Load status   |
|----------------|----------------|
| error.js       | Okay |
| guildCreate.js | Okay |
| guildDelete.js | Okay |
| message.js     | Okay |
| ready.js       | Okay |
'---------------------------------'
Bot logged in as `Joker#0156`, user ID: `484988029841440808`
`sydney`
^C
C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot>node .
Template locale file found, ignoring
.----------------------------.
|          Commands          |
|----------------------------|
|  Command  |  Load status   |
|-----------|----------------|
| ping.js   | Okay |
| server.js | Okay |
| whois.js  | Okay |
'----------------------------'
.---------------------------------.
|             Events              |
|---------------------------------|
|     Event      |  Load status   |
|----------------|----------------|
| error.js       | Okay |
| guildCreate.js | Okay |
| guildDelete.js | Okay |
| message.js     | Okay |
| ready.js       | Okay |
'---------------------------------'
Bot logged in as `Joker#0156`, user ID: `484988029841440808`
`sydney`
[
  '#locale{commands:serverinfo:query:footer}',
  'commands:serverinfo:query:footer',
  index: 0,
  input: '#locale{commands:serverinfo:query:footer}',
  groups: undefined
]
(node:43844) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of null
    at resolveLocale (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\functions.js:196:47)
    at Object.run (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\commands\info\server.js:35:24)
    at run (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\events\message.js:59:30)
    at Client.emit (events.js:223:5)
    at MessageCreateHandler.handle (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:223:5)
(node:43844) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a 
catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:43844) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
^C
C:\Users\Marek Poláček\Documents\GitHub\Joker-Discord-Chat-Bot>