Send a message to all users when the bot wake up - python

I've started tinkering with python recently and I'm on my way to create my very first telegram bot mainly for managing my Raspberry Pi and a few things connected to it. The bot is done but I would like to send a message to all the users that have already interacted with the bot when it starts, basically saying something like "I'm ready!", but I haven't been able to find any information about it.
Is there any specific method in the API already done to do this? Or should I create another file to store the chat_id from all the users and read it with python?
Thank you all for your help!! Regards!

You should have a Database that stores Chat-id(s) of Clients that interact with your bot.
If you're able to put them into a list, then the job is half done.
All you need to do is to create a "for loop", and send message to all the ID(s) in the list.
Example:
message = "Good morning"
chats =[1234447488,3748838477,4748848578,7463638488]
for chat in chats:
bot.send_message(chat_id=chat,text= "message")
In case of of clients that have deleted your bot, you may experience an error. You can catch that with try and except.

Is there any specific method in the API already done to do this?
No, there's no such method.
Or should I create another file to store the chat_id from all the users and read it with python?
Yes, you should handle it yourself. Usually user ids and another information about User <-> Bot interaction is stored in a database on a server, because it's easier for maintaining and searching.
So if you want to send a plain text message to your users in a file, you should call SendMessage method of telegram bot API for every user in your file.

You should save users in database or file.After that use for to send_message one by one to all users that you have in database or file.

Yes you should create another file or use a database to store the chat_id of all the users you interact with. You can check Telegram Bots API to see all the available commands. if there is no such command then there probably won't be any command in the wrapper you are using for python either.

Related

Is there a way to find if someone your server in Discord belongs to a particular server?

I was looking for a way if you can find all the members from a particular server in discord to let's say remove them from your server as they can be from your opponents' server lurking around. If there is a way I want to create a discord bot for it. Any help related to it will be appreciated.
Yes there is, but this would require that the user authorizes your application. It would work something like this:
Your bot has some sort of webserver listening
Your bot gives them a link
They click the link, discord asks them to authorize your bot
Discord redirects them to your webserver with a token in the parameters
Using that token, you can access info such as what guilds they are in.
This is easiest if you already have a bot dashboard, but can still be achieved without one (though you still need a webserver to listen for the callback).
If you have a quart webserver (which is how I would recommend doing it) then take a look at this: https://github.com/jnawk/Quart-Discord
Edit: Also note that, if your bot is in this other guild, you can do a simple check, like this:
g = bot.get_guild(guild_id)
await g.chunk()
if member in g.members:
# ban them

discord.py: Hide messages from all other users, but the #mention user

I'm developing a matchmaking bot for discord. I read through the documentation and looked through stack exchange, I can't find relevant information on this. I'm trying to eliminate clutter and make it easier for a users to accept and decline a matchmaking request. The bot would listen for a "!match #user" and handle the event. I only want the #user to see and accept it and the user that sent the message to see it (obviously). Right now, I believe it's not possible unless it assigns a secret role and deletes these roles after they are finished; this wouldn't be ideal though. Any information or forward to a post, that would help tremendously. Thanks in advance.
You can not currently hide messages for any specific user/role.
You can try 2 approaches:
Send Message in User DMs
Make a channel and set it permissions for a specific role and assign that role to the user

Is it possible to get all channels a slack bot is allowed to write?

I am trying to build a slack bot based on heroku and python which writes messages every 10 minutes to all channels the bot is allowed to write messages. It would be perfect if I could just read from the slack api to which channelId's the bot is connected and let the bot post the message to all channels at the same time.
Till now I couldnt find such function in the slack api. On the other hand I have to addmit that I am pretty new to slack. Is there a similiar function out there or can you think of a work around? If possible I would like to avoid storing data additionally somewhere.
Yes there is. Call users.conversations with your bot token to get the list of channels it is a member of.
From the documentation:
This method helps answer questions like:
Which conversations am I a member of?
Which public channels is my bot user in?
Do I have any direct messages open with my friend Suzy?
Is my bot a member of any private channels?

How to login as user rather bot in discord server and run commands?

Slack API provides you two options: use app as a bot and as a logged in user itself. I want to create App that will be working as a user and run channel commands. How can I do with discord.py?
Discord.py is no longer maintained to work on user accounts, so given the recent updates in the user api, it is no longer the ideal framework which selfbots should be written in.
There are a number of selfbot api libs out there, but the best one that's written in python is this: https://github.com/Merubokkusu/Discord-S.C.U.M
P.S. selfbotting against tos - so be careful (respect rate limits and don't act like a bot)
As Wright has commented, this is against discord's ToS. If you get caught using a selfbot, your account will be banned. However, if you still REALLY want to do this, what you need to do is add/replace bot.run('email', 'password') to the bottom of your bot, or client.run('email', 'password') to the bottom depending on how your bot is programmed.

how can i join two users in a telegram chat bot?

I am going to make a telegram bot in Python 3 which is a random chat bot. As I am new in telegram bots, I don't know how to join two different people in a chat bot. Is there a guide available for this?
If I understood the question, this isn't really about the code but the idea behind it, right?
My way would be:
Someone start the bot (ill call it 'current user' from now on), you get the userID of the new user and store it somewhere (a json file will do the trick)
The current user wanna talk with some other user so you pull off a random userID from the json file and you store it in some variables that are unique for the current user. You also do the same thing for the receiving user
Any new message from the current user will go through the bot and will be replied to the receving user
Quick tip: Use a python wrapper of the Telegram Bots Api, my suggestion would be python telegram bot. Its really good and offers some really neat features to help you (for example you can set user-specific data with pass_user_data). Feel free to check it out!
You need to make a database with chatID as primary column. and another column as partner. which stores his/her chat partner chatID.
now when a user sends a message to you bot you just need to check the database for that user and send the message to her chat partner.
after the chat is done you should empty partner fields of both users.
And for the picking part. when a user wants to find a new partner, choose a random row from your database WHERE partnerChatID is Null and set them to first users ID and vise versa.
I am not sure to understand your question, can you give us what you pretend to do more explained?
You have a few options, creating a group and adding the bot to it.
In private chat you only can talk with a single user at a time.

Categories

Resources