首页 > 解决方案 > 我的硬币翻转功能没有输出任何东西

问题描述

(忽略愚蠢的消息回复,内部笑话) - 我想知道为什么我的硬币翻转不起作用。我的第一个消息功能可以正常工作,没有任何问题,但硬币翻转一个根本不起作用。(我已经包含了几乎所有经过审查的完整代码)这是在 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();
     }
 }

标签: javascriptdiscorddiscord.js

解决方案


var flip = Math.floor(Math.random());总是给你0。
你可能想要Math.round(Math.random())


推荐阅读