Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:22:17+00:00 2026-06-15T15:22:17+00:00

I was trying to create an IRC bot written in Javascript + NodeJS. This

  • 0

I was trying to create an IRC bot written in Javascript + NodeJS. This bot should be able to load plugins while running and should be able to reload the same plugin after changes etc.

What works?

Loading files at runtime + executing its code.

What’s wrong?

After loading the same plugin again if still executes my code, but now it happens twice or nth times I load the plugins.

Current code:

bot.match(/\.load/i, function(msg) {
    require('./plugins/plug.js')(this);
});

module.exports  = function(bot) {
    bot.match(/\.ping/i, function(msg) {
    msg.reply('pong');
});

So, is there any way to fix my issues and make this work?

P.s. I’m using IRC-JS as a base for this bot.

updated, fixed:

Even changes to that file are ignored, so it must be something like a
cache.

Fixed by clearing the require.cache

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:22:18+00:00Added an answer on June 15, 2026 at 3:22 pm

    To answer my own question. While loading plugins, I add every object to a global array. This can be easily accessed and deleted afterwards.

    function clearplugins() {
        require("fs").readdirSync("./plugins/active").forEach(function(file) {
            delete require.cache[require.resolve("./plugins/active/" + file)];
        });
    
        plugins.forEach(function(obj) {
            obj();
        });
    }
    
    function loadplugins() {
        require("fs").readdirSync("./plugins/active").forEach(function(file) {
    
            if(file.slice(-2) == 'js') {
                plugins.push(require("./plugins/active/" + file)(bot));
                console.log(file+' loaded');
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an IRC Bot, below is the code, however, when
I've been trying create this simple ish to-do list web app using JavaScript &
I have an IRC bot and I'm trying to create a new thread to
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Trying to create a background-image slideshow and am getting this error... This is the
I'm having a bit of a problem. I am trying to create an IRC
I'm using a IRC bot written in procedural PHP that was originally created by
I'm trying to set up an IRC bot using ActiveRecord on the back end
I am trying create cpu load generator tool. In which my input will be
I'm trying create this function such that if any key besides any of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.