Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to block an entity like user or bot with a user account. I cannot find any method for that. Also, it's good to exist some method for unblock entities.
You need to use what is known as raw API. Searching for "block" takes us to BlockRequest which comes with an example:
from telethon.sync import TelegramClient
from telethon import functions, types
with TelegramClient(name, api_id, api_hash) as client:
result = client(functions.contacts.BlockRequest(
id='username'
))
print(result)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
I would like to create a bot that sends a request (post) via a command /refresh with certain information so where I say /refresh test and it then sends a POST with certain information that is given for the time being.
Like this
client_id=CLIENT_ID_HERE&client_secret=CLIENT_SECRET_HERE&refresh_token=REFRESH_TOKEN_HERE&grant_type=refresh_token&redirect_uri=REDIRECT_URI_HERE
but don't know how.
So I reread this now many times. If I understood it right now, you just want to post something to, for example https://example.com/post
If so, then use aiohttp and create a client session and post it.
import aiohttp
#this in your command
async with aiohttp.ClientSession() as session:
await session.post(“https://example.org/post“, data={“foo”:”bar”})
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am creating a system the detects if a bot sent my bot a message, if so, it'll alert me to my server with a webhook. But unfortunately, it hasnt been working.
I tried message.user.bot but it doesn't work the way I intended it to. Is there a correct function to determine if the message author is a bot?
Use message.author.bot.
For example this:
#bot.event
async def on_message(message):
if message.author.bot:
pass # whatever here
await bot.process_commands(message)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I want to send a message to everybody on my friends list via python I want to do it without there id's is there a way to do this?
Users' friend lists are not exposed to the public API. Even if they were, mass DM-ing users is against Discord's Terms of Service.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Please explain how to get user.id and user.name of client who talking with my bot in balebot. There is a peer class, but i don't know how exactly it works?
its a simple way to use get_effective_user() function to get peer_id or accesshash, see:
user_peer=update.get_effective_user()
user_id = user_peer.peer_id
But if you need more you can get name and other feilds of user from an Update Json. like this :
def text_received(bot, update):
for user in update.users:
print(user.get_json_object())
....
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have been writting a socket server in python. I want to send data to some users (no to all) but I dont know how to do it. Can i send it with a for loop?
For example:
some_clients = [client1, client2, client5, client9]
for client in some_clients:
client.send("data")
It is good?
If that works, it's perfectly OK.
If you want something more readable, you could do:
for client in filter(shouldrecieve, all_clients):
client.send(data)
or something like:
for client in (client for client in all_clients if client.attrspam == barfoo):
client.send(data)