繁体   English   中英

Discord bot .js 查询选择器

[英]Discord bot .js queryselector

我正在尝试在我的不和谐机器人中实现一个 js 代码。 所以我在网上拿了一些代码来尝试它是否有效,现在,我正在尝试使用这样的查询选择器:

if (msg.content === "!GuessNumber"){
    let randomNumber = Math.floor(Math.random() * 100) + 1;
      const guesses = document.querySelector('.guesses');
      const lastResult = document.querySelector('.lastResult');
      const lowOrHi = document.querySelector('.lowOrHi');
      const guessSubmit = document.querySelector('.guessSubmit');
      const guessField = document.querySelector('.guessField');
      let guessCount = 1;
      let resetButton;

但我有这个错误

ReferenceError: document is not defined
    at Client.<anonymous> (/Users/zep/Documents/GitHub/Bot-discord/my-bot/index.js:18:23)
    at Client.emit (events.js:311:20)
    at MessageCreateAction.handle (/Users/zep/Documents/GitHub/Bot-discord/my-bot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (/Users/zep/Documents/GitHub/Bot-discord/my-bot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (/Users/zep/Documents/GitHub/Bot-discord/my-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (/Users/zep/Documents/GitHub/Bot-discord/my-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:435:22)
    at WebSocketShard.onMessage (/Users/zep/Documents/GitHub/Bot-discord/my-bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
    at WebSocket.onMessage (/Users/zep/Documents/GitHub/Bot-discord/my-bot/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:311:20)
    at Receiver.receiverOnMessage (/Users/zep/Documents/GitHub/Bot-discord/my-bot/node_modules/ws/lib/websocket.js:801:20)
[nodemon] app crashed - waiting for file changes before starting...

有人可以帮我调试这个并使用https://github.com/mdn/learning-area/blob/master/javascript/introduction-to-js-1/first-splash/number-guessing-game 中的代码。 html为我的机器人? 我来试试它是如何工作的,谢谢

嗯,你不能用

      const guesses = document.querySelector('.guesses');
      const lastResult = document.querySelector('.lastResult');
      const lowOrHi = document.querySelector('.lowOrHi');
      const guessSubmit = document.querySelector('.guessSubmit');
      const guessField = document.querySelector('.guessField');

因为“文档”可以在支持 HTML 的 javascript 文件中使用。

您可以在https://discord.js.org 上搜索它的替代品,因为它可能会有所帮助。 我也会检查自己。

我实际上无法理解您到底想在那里做什么,您是想让用户(执行命令的人)猜测数字,还是想让机器人通过机器人猜测用户的号码.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM