How to join an irc bot in more than one channel? - python

I have designed an irc bot using python.
Here is the code for that bot:-
https://github.com/sheeshmohsin/theb0t/blob/sheesh/ekan0ra.py
It is working fine but it is joining in one channel and i have to made it to join in more than one channel. Please give me ideas or the way i can do it.

You can use the JOIN command, either multiple times for each channel, or as documented in RFC 1459:
self.sendLine("JOIN #channel1,#channel2,#channel3")
Optionally you may include keys:
self.sendLine("JOIN #channel1,#channel2,#channel3 key1,,key3#")
This example demonstrates joining three channels where the second channel has no key.

Related

Discord.py mention application command

I am trying to make a help menu for my discord bot, and would like to make it similar to MEE6's, where it mentions application commands.
But rather than typing myself each command by hand, I would like to automate the process, so that if I add a new command it automatically adds it to the list.
I can easily obtain the commands with tree.get_commands(), but I don't know how to mention them: I found that typing "</command_name:command_id>" works, but I find nowhere on the docs how to get the id of an application command. Currently the only way I know of is with Discord Developer Mode.
Is there something I'm missing?
For anyone who ecounters this problem: I was not using the correct command.
I wanted to get type discord.AppCommand, but tree.get_commands() returns discord.Command.
So you get all the Application Commands using await tree.fetch_commands(), and those actually have the id that can be used to mention the command.

Grabbing a list of all Public and Private channels within Slack

I'm in the process of writing a python bot that does a number of things for me, one of those things is to display every channel within my workspace along with the member count. This isn't that complex and as of now I'm able to do this but only for public channels. Having a read through the conversations.list API documentation it points to using a solution like:
result = slack_client.conversations_list(exclude_archived=1, types="public_channel, private_channel")
Now, when attempting to use the above it will call, but it'll only grab public, it does however exclude archived channels as I expect. I've tried different combos and have gotten nowhere. Is this something no longer supported or am I missing something obvious?
Additionally, we're on the plus plan of Slack.

Can someone help me better understand zero or one in regex and possibly with nesting another within the same regex statement

So I am creating a regex to recognize commands for a basic IRC and have come to one command that is giving me some trouble and has made me think about my previous commands a bit and possibly might allow me to correct some mistakes.
Essentially a JOIN message in this sense will allow a user to be added to a channel for chat with others, and for the purpose of this project a JOIN will also create the channel and add the user as its first member. The user is already assumed to be logged in before this point so the only information needed is the channel or channels they intend to join. This is where the problem comes where the RFC manual on IRC doesn't really have a hard limit so I think I will have to set some sort of soft limit of channels for them to join which.
JOIN #foobar ; Command to join channel #foobar.
JOIN #foo,#bar ; Command to join channels #foo and #bar.
These are two examples of possible basic commands. Each must have no spaces, channels are delimited by a "," and a channel must begin with a special character being '&', '#', '+' or '!'.
I don't know if it would be something along the lines of the following would be what im looking for
"JOIN\s[(&|#|+|!)\w+][,(&|#|+|!)\w+]{0-4}"
The way I understand this setup if I did it correctly is there should be one channel followed 0 to 4 other, separated channels which I feel like would be easy to parse and work with due to the commas. Can someone let me know if this is on the right track?
Also as an additional note, in previous commands I've tested for an exact correct command in terms of parameters but as long as there is a space is after the JOIN it should recognize it as a command but may just have incorrect parameters. I would assume if the above regex was correct that something like this might be the correct way to deal with that.
"JOIN?[\s[(&|#|+|!)\w+][,(&|#|+|!)\w+]{0-4}]"
I could be way off but alot of these special symbols get fairly confusing.
I think you're looking for something like JOIN\s[&#+!]\w+(,[&#+!]\w+){0,4}
There were a couple of issues in your original. [] don't quite do what you think they do, and the separator in {} syntax is a comma, not a hyphen.
Is there a reason you're limiting yourself to only five channels?

How to make my Discord bot respond to both custom prefixes and mentions when I use a function to get the prefix?

I would like to preface this with saying that I asked this question previously and it got closed, marked as a duplicate. I saw those other questions before. I tried those solutions. They didn't work. They don't work with prefix functions, only prefix strings. This is why I asked the question. I have reworded a few things, added info to the title, as much as I can think of to get this question through so I can get the answer I need. Please, please do not close this one. I want an answer that works.
I have a function that retrieves a custom prefix from a database file, but I would like to implement the ability to also respond to mentions, as in the when_mentioned() function. However, I can not pass in both functions to the command_prefix parameter when I am initializing my bot, nor can I add my prefix function to the when_mentioned_or() function to combine the two. Is there any way I could go about doing this? I've been searching for answers for the last hour and have found nothing that works yet.
You can simply use the when_mentioned function in your own function that retrieves a custom prefix. You can call it with the same bot and msg that you're passed and it will return a list of the mention formats (for with and without a nickname) that you can use. You can then return that list with your custom prefix appended.
Alternatively, you can simply directly return a list with your custom prefix, bot.user.mention (see the documentation for Bot.user and ClientUser.mention), and the nickname format for that mention (<#!{user_ID}> rather than <#{user_ID}>; see the documentation for ClientUser.id).

discord.py - Obtaining channel object from mentioned channel

I am looking for a way of which I can obtain the name and ID of the channel, from when someone sends a command followed by a channel mention, such as --command #CHANNEL. I have seen this done on other public bots, but I have, as of yet, found no way to reproduce this. This is probably a stupid question, but I would highly appreciate any help or thoughts you could put towards this.
Thanks in advance,
Nat.
You would need to make sure a channel is an expected parameter in the command definition. This code creates a command for the bot called 'test' that expects an object of the discord.Channel class to be passed as a parameter:
bot.command()
async def test(channel: discord.Channel):
You could then get the name and id using channel.name and channel.id, respectively.

Categories