javascript - 我的硬币翻转功能没有输出任何东西
问题描述
(忽略愚蠢的消息回复,内部笑话) - 我想知道为什么我的硬币翻转不起作用。我的第一个消息功能可以正常工作,没有任何问题,但硬币翻转一个根本不起作用。(我已经包含了几乎所有经过审查的完整代码)这是在 VSC 中使用 JS、Node 和 Discord.js。
console.log('gamercum');
const Discord = require('discord.js');
const client = new Discord.Client();
client.login('ODUwMDI5MjUxMzIyNTc2OTI0.YLjxbg.EZBRMra3o8Srs4gBCwLz_1NQgTU');
client.on('ready', readyDiscord);
function readyDiscord() {
console.log('boolin');
}
function coinFlip() {
var flip = Math.floor(Math.random());
if(flip = 1) {
msg.reply('heads');
} else {
msg.reply('tails');
}
}
client.on('message', gotMessage);
function gotMessage(msg) {
console.log(msg.content);
if(msg.content === 'gamercum' || msg.content === 'Gamercum' || msg.content === 'gamer cum'
|| msg.content === 'Gamer cum') {
msg.reply('we pimp chimpin');
}
}
client.on('message', getMessage);
function getMessage(msg) {
console.log(msg.content);
if(msg.content === 'coinflip') {
coinFlip();
}
}
解决方案
var flip = Math.floor(Math.random());
总是给你0。
你可能想要Math.round(Math.random())
推荐阅读
- python - Python Scrapy - 产量不起作用,但 print() 确实
- anylogic - Anylogic:流中的系统动力学和随机性(三角形或正态)给出错误的结果
- python-3.x - super().__init__(damage) 未定义变量
- database - 如何将数据库从安装移动到新安装
- javascript - 如果 React Native Function 中的 prop 发生变化,则渲染
- linux - 出现错误:运行 cloudtracker --account demo --list users 时无法从配置文件 config.yaml 加载 yaml
- express - Express.js 的 next() 函数究竟做了什么,在 express 包中的具体位置是什么?
- django - '“错误:未找到 .egg-info 目录”在部署到 heroku 期间
- sql - 为什么将用户函数中的数据插入表变量时使用临时表更快?
- html - 如何在嵌套表上添加位置粘性?