Giter Site home page Giter Site logo

Comments (2)

henry40408 avatar henry40408 commented on September 27, 2024 3

@SomethingGeneric I encountered the same error and figure our a quick solution.

The issue arises because MultiChannelBot extends SingleServerIRCBot. When you define self.channels in the __init__ function of MultiChannelBot, it overrides self.channels in SingleServerIRCBot. As a result, SingleServerIRCBot fails to add channels to self.channels as a IRCDict, which is now a list overridden by MultiChannelBot.

import irc.bot

class MultiChannelBot(irc.bot.SingleServerIRCBot):
    def __init__(self, channels, nickname, server, port=6667):
        print("Initializing bot...")
        server_list = [(server, port)]
        super().__init__(server_list, nickname, nickname)
        # 👇  MultiChannelBot overrides self.channels, which is also used by SingleServerIRCBot
        # self.channels = channels
        self.my_channels = channels # rename to my_channels
        print("Bot initialized!")

    def on_welcome(self, connection, event):
        print("Joining channels...")
        for channel in self.my_channels: # rename to my_channels
            connection.join(channel)

    def on_pubmsg(self, connection, event):
        print("Found public message!")
        message = event.arguments[0]
        user = event.source.nick
        channel = event.target

        if message.startswith("!hello"):
            connection.privmsg(channel, f"Hello, {user}!")

    def on_privmsg(self, connection, event):
        print("Received private message!")
        message = event.arguments[0]
        user = event.source.nick

        if message.startswith("!private"):
            connection.privmsg(user, f"Hello, {user}! This is a private message response.")

if __name__ == "__main__":
    print("Defining bot...")
    channels = ["#general", "#znc", "#bots", "#roadmap"]  # Add more channels as needed
    bot = MultiChannelBot(channels, "goobot", "goober.cloud")
    print("Starting bot...")
    bot.start()

SingleServerIRCBot also uses self.channels to manage joined channels:

irc/irc/bot.py

Line 162 in 5aa529d

self.channels = IRCDict()

irc/irc/bot.py

Line 208 in 5aa529d

self.channels[ch] = Channel()

The quick solution is give self.channels another name e.g. self.my_channels.

from irc.

SomethingGeneric avatar SomethingGeneric commented on September 27, 2024

Not sure if this is a user error or library error?

from irc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.