Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.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的音乐机器人存在问题_Javascript_Node.js_Discord_Discord.js_Bots - Fatal编程技术网

Javascript 使用discord.js的音乐机器人存在问题

Javascript 使用discord.js的音乐机器人存在问题,javascript,node.js,discord,discord.js,bots,Javascript,Node.js,Discord,Discord.js,Bots,我在创建一个基本的discord机器人(用于播放音乐)时遇到了一些错误。我主要依赖于文档——我想我复制并粘贴了discord.js文档示例中“脱离上下文”的某些代码行。但我不知道它们可能是什么,因为我对编程还是很陌生 我安装并导入了所有必要的依赖项,所以这不是问题所在。 我的机器人工作正常(收听和回复MSG) 这是与音乐功能相关的代码 client.on("message", async message => { const prefix = '?' con

我在创建一个基本的discord机器人(用于播放音乐)时遇到了一些错误。我主要依赖于文档——我想我复制并粘贴了discord.js文档示例中“脱离上下文”的某些代码行。但我不知道它们可能是什么,因为我对编程还是很陌生

我安装并导入了所有必要的依赖项,所以这不是问题所在。 我的机器人工作正常(收听和回复MSG)

这是与音乐功能相关的代码

  client.on("message", async message => {
  const prefix = '?'
  const args = message.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();

  if (command === 'play') {
    let track = await client.player.play(message.member.voice.channel, args[0], 
    message.member.user.tag);
    
    message.channel.send(`Currently playing ${track.name} as requested by 
    ${track.requestedBy}`);

  }

  if (command === 'stop') {
    let track = await client.player.stop(message.guild.id);
    message.channel.send('Stopped.')
  }


})
这是我得到的错误:

    (node:436) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'play' of undefined
    (node:436) 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(). To terminate the node process on unhandled promise 
    rejection, use the CLI flag `--unhandled-rejections=strict` (see 
    https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
    (node:436) [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.
可能是:

  • 机器人需要先进入通道?(这意味着我需要编写一个连接通道函数?)
  • 前缀有问题吗?我的config.json文件中定义的前缀是
    “prefix”:;ntek“,
    我确实尝试过将前缀更改为该前缀,将其完全删除,以及一系列其他事情,但似乎没有任何事情能够使bot正常工作
  • 异步函数中存在语法错误(或缺少某些内容)

  • 请使用本侧解释和显示的代码进行尝试:

    首先,您需要创建一个语音频道连接,然后才能播放内容…
    一切都应该在网站上解释。
    希望我能帮忙;)

    ShadowLp174

    客户端。播放器
    不是什么东西。