create a constant fuction in telebot - python

I am creating a telegram bot using telebot and i want to make a function that will work constantly regardless of whether a person writes something to bot or not. How can i make it? In this function i want to place a code that will check the time everytime.
I've tried to add a "constant" fuction to all the others, but thats not what i need.
Should i make it in decoraters like
`#bot.message_handler()`

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.

Set a flag on message for identification

I am looking for a way to set a flag or some kind of identifier on a discord.Message object so that later, for example if a reaction is added, I could identify it as a certain type and do something with it. I need something similar to discord.MessageFlags, but with the option to set the key myself, or ideally even make it of arbitrary type (not Just Boolean).
Is there anything built in that I could use, or some hacky solution?
Also, if someone asks, I don't want to set up a database.
Edit: Alternatively is there a way to see if a certain bot command have sent a particular message?

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).

How do you make it possible to make accounts? Python

I want to make a simple game on python, all text based. Sort of an interactive story with puzzles etc. but it is likely to be long. I want to be able to it possible for poeple to sort of, 'Save Progress'. Perhaps assign them selves a name etc? I am new to Python and am wondering if it is possible to set up a bank containing details of game play that can be accessed by entering a username and so will load the correct area of the code to allow the player to pick up where they left of.
Say they decided to quit the game just after... say, finding a clue to a murder. The computer would store the line of code they were on and get them to enter their name. Next time they could select 'Load' from the start up menu and then enter their name. The computer would then search for their name and pull up the peice of code they were at and continue as normal from there.
I am new at this so please try and explain simply. I can make a menu etc. no problems with the if's etc and make the story it's self. It is just the loading I want to add.
I hope this isn't tooooo complicated!? Please help me!
You should check out the pickle module. It allows you to store/retrieve any python object. One way to do this would be to have your game take place in a class, where all of the states/etc were members of that class (or derived classes). When they wanted to save you would just pickle your class!
You are pretty new to python, I would recommend reading the documentation provided here: http://docs.python.org/tutorial/ .
Python tries to be both easy to learn and comprehensive. Most questions answer themselves!
Depends on how you create your game...
Do you follow the tree of decisions that the user took in the game? If so you save the decisions in a file, that you save to a location (for example "saves/{username}/{name_of_save}.sav or just "saves/{username.sav} if every username should have only one save, but this is just a example it all depends on you). You could then allow them to select their save file and then simulate the actions from the file till you reach the point where the last decision took place.
If you would like to easily save the data to the file(s) you could also use a format like JSON, which python has built-in support for - read more at http://docs.python.org/library/json.html . This will allow you to easily create objects that you want to save/read from the file and use for processing.
Hope that helps...
Just a Idea, I have not actually tried anything like this
Take a look at http://www.sqlite.org/ or use plain text files for the beginning:) you could use the username:bitfield to encode you progress. Or use the ConfigParser module for Python and create a scetion for each user:) have fun learning:)

Categories