简体   繁体   中英

Discord bot .js queryselector

I'm trying to implement a js code in my discord bot. So I take some code on the net to try if it was working and now, I'm trying to use queryselector like this :

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;

But I have this error

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...

Can someone help me to debug this and use the code from https://github.com/mdn/learning-area/blob/master/javascript/introduction-to-js-1/first-splash/number-guessing-game.html for my bot ? I this to try how it works , Thanks

Well, you cannot use

      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');

Because "Document" is something that can be used inside a HTML-supported javascript file.

You may search for a replacement to this at https://discord.js.org as it might help. I will also check myself.

I actually am not able to understand what exactly you are wanting to do there, Do you want to make the user (the person who executes the command) guess the number, or you want the bot to guess the number of the user by the bot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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