简体   繁体   English

制作 Discord.js 机器人时出现错误“错误:找不到模块‘随机’”

[英]I am having an error “Error: Cannot find module 'random'” while making a Discord.js bot

Please help with the following issue.请帮助解决以下问题。

I am making a Discord.js bot, but, when I start the bot using "node."我正在制作一个 Discord.js 机器人,但是,当我使用“节点”启动机器人时。 it gives the following error:它给出了以下错误:

internal/modules/cjs/loader.js:1068
  throw err;
  ^

Error: Cannot find module 'random'
Require stack:
- D:\quote\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1065:15)
    at Function.Module._load (internal/modules/cjs/loader.js:911:27)
    at Module.require (internal/modules/cjs/loader.js:1125:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at Object.<anonymous> (D:\quote\index.js:2:16)
    at Module._compile (internal/modules/cjs/loader.js:1236:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)
    at Module.load (internal/modules/cjs/loader.js:1085:32)
    at Function.Module._load (internal/modules/cjs/loader.js:950:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'D:\\quote\\index.js' ]
}

My code:我的代码:

const Discord = require('discord.js');
const random = require('random');

const bot = new Discord.Client();

var stats = {};

bot.on('message' , (message) => {
    if (message.guild.id in stats === false) {
        stats[message.guild.id] = {};
    }

    const guildStats = stats[message.guild.id];
    if (message.author.id in guildStats === false) {
        guildStats[message.author.id] = {
            xp: 0,
            level: 0,
            last_message: 0
        };
    }

    const userStats = guildStats[message.author.id];
    userStats.xp == random.int(15, 25);

    const xpToNextLevel = 5 * Math.pow(userStats.level, 2) - 50 * userStats.level + 100;

    console.log(message.author.username + 'now has' + userStats.xp);
    console.log(xpToNextLevel = ' XP needed for next level.');

const parts = message.content.split(' ');

if(message.content === '!hello') {
    message.reply('hi');
 }
});

bot.login('REMOVED');

You're trying to load a module that you haven't installed.您正在尝试加载尚未安装的模块。 Try running npm i random in the console in the same directory.尝试在同一目录的控制台中npm i random

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Discord.js 时出现“错误:找不到模块” - “Error: Cannot find module” While Using Discord.js discord.js 中的机器人运行错误(错误:找不到模块/代码:'MODULE_NOT_FOUND',requireStack:[]) - Bot running error in discord.js (Error: Cannot find module / code: 'MODULE_NOT_FOUND', requireStack: []) Discord bot可以很好地在本地托管,但是如果我尝试将其托管在heroku上,它会显示“错误:找不到模块&#39;discord.js&#39;” - Discord bot works fine hosted locally but if i try and host it on heroku it says “Error: Cannot find module 'discord.js'” 我正在制作一个 discord.js 机器人,我想知道是否有错误 - I am making a discord.js bot and I want to know if there was an error 我在 discord.js 中制作头像机器人时出错 - I'm getting an error in making avatar bot in discord.js 我有一个我不明白的错误。 它在 Discord.js 中,我正在制作一个只为我的服务器做事的机器人。 我是 discord.js 的新手 :) - I have an error that I do not understand. It is in Discord.js, and I am making a bot that does things only for my server. I am new to discord.js :) 我正在尝试使用 discord.js 制作一个 discord 机器人,我正在制作一个偶数处理程序,但我收到此错误 - i am trying to make a discord bot using discord.js and im making an even handler but im getting this error 错误:在线主机上找不到模块“discord.js” - Error: Cannot find module 'discord.js' on online host 在 discord.js 中执行状态命令时出现错误 - I get error while making a status command in discord.js 禁止模块,Discord 机器人错误.. discord.js - Ban module, Discord bot error.. discord.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM