[英]document.querySelector in a discord.js bot
我想將本地站點與 discord.js 機器人連接起來,所以如果我想做的事情有效,請將其在線放在服務器中。
我想在 discord 服務器通道中發送輸入值。
js: src/bot/index.js
const { Client, Intents } = require('discord.js');
const { TOKEN } = require('./config.json');
channelid = "925049593056596009"
const client = new Client({ intents: 32767});
client.once('ready', () => {
console.log('Ready!');
});
function test() {
document.querySelector('.button').addEventListener('click', () => {
channelid.send(document.querySelector('.input').value)
})
}
test()
client.login(TOKEN);
html:src/html/application.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Applications</title>
</head>
<body>
<script src="../bot/index.js"></script>
<form>
<input class="input" type="text" placeholder="say something">
<button class="button">OK</button>
</form>
</body>
</html>
錯誤:
document.querySelector('.button').addEventListener('click', () => {
^
ReferenceError: document is not defined
從此鏈接require.js將 require.js 添加到您的項目
然后加載 discord.js 和你的 index.js 如下
<,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Applications</title> </head> <body> <script data-main="./src/discord.js" src="./src/require.js"></script> <script data-main="./src/index.js" src="./src/require.js"></script> <form> <input class="input" type="text" placeholder="say something"> <button class="button">OK</button> </form> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.