const tmi = require('tmi.js');
// Define configuration options
var x = "asdfasdf"
const opts = {
identity: {
username: 'username',
password: 'password'
},
channels: [
"rabeya74"
]
};
// Create a client with our options
const client = new tmi.client(opts);
// Register our event handlers (defined below)
client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler);
// Connect to Twitch:
client.connect();
// Called every time a message comes in
function onMessageHandler(target, context, msg, self) {
if (self) {
return;
} // Ignore messages from the bot
// Remove whitespace from chat message
const commandName = msg.trim();
// If the command is known, let's execute it
if (commandName === '!dice') {
const num = rollDice();
client.say(target, `You rolled a ${num}`);
document.body.innerHTML = x;
console.log(`* Executed ${commandName} command`);
document.body.innerHTML = `You rolled a ${num}`;
window.onload = function() {
document.getElementById("display").innerHTML = "hello";
}
document.getElementById("display").innerHTML = "hello";
} else {
console.log(`* Unknown command ${commandName}`);
}
}
// Function called when the "dice" command is issued
function rollDice() {
const sides = 6;
return Math.floor(Math.random() * sides) + 1;
}
// Called every time the bot connects to Twitch chat
function onConnectedHandler(addr, port) {
console.log(`* Connected to ${addr}:${port}`);
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script src="bot.js"></script>
<div id="display"></div>
</body>
</html>
我正在尝试制作一个小型抽搐javascript应用程序,当我掷骰子时会更新HTML文件。我尝试了document.body.innerHTML文件的每个版本,但它根本不想更新。是因为它在函数中吗?似乎什么也没显示。
答案 0 :(得分:1)
您无法在浏览器中使用require()
。由于未定义require
,因此此代码会产生错误。尝试在<script src="tmi.js"></script>
元素中添加<head>
。