Py-cord command won't let go - python

I have been trying to update my discord bot to discord.py v2.0 and wanted to switch over to slash commands and cogs. When trying different techniques of achieving this I once used py-cord. I created a test command called latency and it worked but since I struggled with py-cord I uninstalled py-cord and found a new technique. The problem is that the latency (my py-cord) command is still there on the list where you can choose what slash command to use and so I wonder how do I remove this from the bot command selection?

When working with slash commands, the discord API registers and deregisters the slash commands on their own servers, and then sets up hooks for your bot.
This means that, when the bot connects, it sends an API call to discord to tell it what commands it has, after which you need to wait for Discord to register that properly. They don't guarantee to do that instantly, not for deletion nor registration.
So, in short, you don't remove it from the bot section; you wait until Discord does that for you. They guarantee that they do that in 24 hours of your bot being online, but, realistically, it's usually done in less than 2.
You can set debug_guilds if you want to register commands faster, which would allow you to have a few guilds (servers) that would get updated first, usually quite close to immediately. However, from my own experience, that helped very little for deletion, as Discord usually took its time for that.
One more advantage of debug_guilds is that, when passed, any new or deleted commands are only registered for those specific guilds, allowing you for more free testing. However, it is not perfect, as changed excising commands are of course still run trough your testing bot.
Instead, my advice would be this: Create a second bot, and use that one for testing stuff. Once it's done, you can update the new bot with the verified code. This way, no one gets annoyed at multiple registered commands and all that! If you know how to use git: just run one bot on the main branch, and the other on the development branch. :-)
I hope this helps! :-)

Related

Update preexisting telegram menus using python

I am building a telegram bot that will automatically add messages to preexisting menus in a bot ( created by Manybot, not with python ) once they are uploaded to a specific channel.
I spent a week or so trying to find a way to update preexisting menus but it can't manage to find a solution.
even when I try to run an infinite loop to monitor any messages to the bot ( using any telegram-python library out there ) i get this error :
Conflict: can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first
and i am forced to delete the webhook , which will in turn disable every command i added to the menus and need to create another bot
I would really appreciate any help .
The problem is not related to existing webhooks, it's the fact that each bot token can poll / webhook only once.
In other words, you can't have two scripts running with the same bot token, regardless if it's long polling or a webhook.
This is a limitation of the Telegram Bot API.
You can only run your own script when the manybot version of your bot is paused, stopped, turned off, etc. The getUpdates method will reject new connections with the same bot token.
You can either use a second bot token to use other commands if your setup allows it, or use the MTProto API with frameworks such as Pyrogram or Telethon.

How to handle messages in a Telegram Bot?

My goal is to make a Telegram Bot using Python that does the following:
The user types a command
The bot explains what the user should type next.
The user types certain information
I use that info to fetch a value in a python dictionary.
The bot replies with that info
I have already created the bot and set the command. The problem is that I don't know how to keep the bot "listening" . I have looked up in the docs but I have only found getUpdates, which gets the user's responses but only when you hit run.
res=requests.get(url=f"https://api.telegram.org/bot{bot_token}/getUpdates")
I would like to set a webhook, and I know there is a method for this but I'm not shure about how this works.
When you are a PHP programmer, setting the webhook through a URL and using setWebhook would do the trick and telegram will send the result to this link whenever a user sends an update to the bot. But, Python programmers have to use a different approach, I think. The main, and while, the easiest approach to make the bot listen permanently to the request is to python-telegram-bot module.
There are a few links that can help to build your first pythonic bot that can respond to users' updates.:
Python-Telegram-Bot Repository, which is the repository of the module.
A few examples of bots created using this module, can give you insight into the process of creating your first bot.
A conversation bot

Trying to code a Discord selfbot to send message from multiple accounts controlled by one master account

Hey so ive been trying to make a selfbot and hopefully slowly learn python along the way. I ve gotten far enough to do it in one account but i want to do it from multiple accounts controlled by a master account with commands and command prefixes. This video shows what i am trying to replicate, just i want to do it in server as well and not necessarily spam that much just one set of message from each account is good enough. https://www.youtube.com/watch?v=1N6cR-FIJgE This is the video. How do i convert the code to use multiple tokens and control those accounts with a master account. https://github.com/casrfgd2/discod - this is the code
Self bots are against Discord's Terms of service and can get your account or in this case multiple accounts banned
What you could do is make a discord bot and use it to the mass dm (which is also kind of against the terms) with just one discord account
To use multiple bots with the same code you could fork the repository per bot and put the different token in your env file every fork

Efficient Way to Run Multiple Instances of the Same Discord Bot (Discord)

I have a Discord bot I use on a server with friends.
The problem is some commands use web scraping to retrieve the bot response, so until the bot is finished retrieving the answer, the bot is out of commission/can't handle new commands.
I want to run multiple instances of the same bot on my host server to handle this, but don't know how to tell my code "if bot 1 is busy with a command, use bot 2 to answer the command"
Any help would be appreciated!
The solution is something called asynchronous code.
This allows the bot to fetch the answer and go do something else such as wait for new commands before executing the next one.
https://docs.python.org/3/library/asyncio.html
I recommend asyncio's python library.
async function myFunction () {}
this should fix your problem
having multiple instances could be possible with threads,
but this is just a much more easy way

django-telegrambot doesn't catch all forwarded messages using WEBHOOK mode

I use django-telegrambot package to make anti-spam telegram bot. The mode for the bot is WEBHOOK
I have some functionality to remove all forwarded messages from chat.
My code looks like:
if update.message.forward_from or update.message.forward_from_chat:
bot.delete_message(chat_id=update.message.chat_id, message_id=update.message.message_id)
return
the code above doesn't work very well, for example when I select a few messages and send them to channel, it deletes only one(sometimes two) messages from forwarded set, sometimes it even doesn't delete if I forward one message, I checked if we always have forward_from and forward_from_chat when forwarding, yes -- we always have it, also I thought I just have some amount of pending_update_count, but it's 0
I know django-telegrambot based on python-telegram-bot package when I have the same code using only python-telegram-bot and run it locally like python main.py it works perfect(catch and delete all forwarded messages)
Did someone face with such error here?
Any thinks/suggestions?
Thanks!
So ok, after investigating I didn't find where is the trouble here, but when I changed the mode from WEBHOOKto POLLING -- it works perfectly without any errors

Categories