Using Python to send messages in Discord - python

Is it possible to make a Python program that sends messages in a Discord chat every 2 minutes, but without other users being able to see that it is a program?

You can make a bot to send message every two minutes using the below code
from discord.ext import commands,tasks
#tasks.loop(seconds=120)
async def determine_winner():
message=#Message to be sent
channel_id=#Gives the id of channel where to send
client.get_channel(channel_id).send(message)
If you want to send this message in multiple channel. You should get the id of each channel where the message to be sent and store it in database or json file and fetch it at the time of sending the message.
But self-botting is against discord'sTOS if they found you self-botting they will ban you from discord permanently

Related

Getting content from a dm in discord.py

So I want to know if it is possible, that a bot gets the content sent to it in a dm and send that in a specifyed channel on a server.
So basically you dm the bot the word "test" and the bots sends the word in a channel of a server
Yes, it is possible for a bot to receive a direct message and then repost the message in a specified channel on a server. This can be done using the Discord API.
You can do the following:
Create a Discord bot and add it to your server. You can do this using the Discord developer portal.
Use the Discord API to listen for messages sent to the bot in a DM. You can do this using the message event and the DMChannel class in the Discord API.
When the bot receives a DM, use the Discord API to repost the message in the specified channel on the server. You can do this using the send method of the TextChannel class in the Discord API.
Yes, this is possible:
First, we use the on_message() event to detect when a message is sent.
We then check if the message is sent in a DM.
If so, we will send a message to a specific channel.
Here is one way you can implement it:
# import ...
bot = discord.Bot(...)
#bot.event
async def on_message(message):
# check if it's
if isinstance(message.channel, discord.DMChannel):
# get the channel from ID
channel = client.get_channel(CHANNEL_ID) # put channel ID here
await channel.send("test") # whatever you want to send
#bot.event:
async on_message(message):
if message.DMChannel:
# define channel and send message to channel.
You can also refer to DOCS.

Why can't I send messages to Telegram bot?

I'm using Telebot to build a simple Telegram bot. I've set up a message handler that responds to commands succesfully, but when I try to send a single message I get an error if I use the chat id (ex: 1234567890):
Error code: 403. Description: Forbidden: bot can't send messages to
bots
I get a different error when I use the user id (ex: #my_user):
Error code: 400. Description: Bad Request: chat not found
This is my code, the auth is correct:
tg_bot = telebot.TeleBot(TG_TOKEN, parse_mode='MARKDOWN')
tg_bot.send_message(chat_id=CHAT_ID_USER, text="hola test")
Is the bot's chat different to the chat I'm supposed to talk with? Any solution and details about the bot functionality will be apreciated, I'm still learning about that!
try this
import telebot
bot = telebot.TeleBot(token)
#bot.message_handler(commands=['start'])
def start(message):
bot.send_message("1395609507","Hello")
bot.infinity_polling()
If the user under this id has not started your bot, then the bot will not be able to write to him/her first. And in this case it is natural to get the error "chat not found". This error can also be observed when working with users who first used the bot and then blocked it.

How to get an old message ID with python telegram bot?

I have a Telegram channel with a bot inside it, which I use to send messages to the channel and edit them with this Python code
import telegram
bot = telegram.Bot(token=MY_TOKEN)
msg = bot.send_message(chat_id=MY_CHANNEL_ID, text="...") # send a message
msg = msg.edit_text("...") # edit the previous message
Sometimes the python bot crashes/closes for whatever reason, when I start the bot again how to recover the ID of a message sent during the previous session so that I'd be able to edit the message again?
I read about this method
bot.edit_message_text(text, chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.message_id)
I guess that for chat_id I have to use MY_CHANNEL_ID but what I don't understand is how to get the message_id of the old message
MANUAL SOLUTION
I found out that the message_id is just the number contained in the post link, so a workaround is to manually copy the post link of a message from the telegram client, for example if the post link is https://t.me/my_channel_name/207 then the message_id is 207 and to edit that message we have to run
bot.edit_message_text(text="...", chat_id=MY_CHANNEL_ID, message_id=207)

Telegram: Send message to bot from different script

I have a telegram bot that handles user input to perform actions on links that are sent.
In my Telegram Bot I have:
def handle_message(bot, update):
url = update.message.text
# do parsing and add url to database
dispatcher.add_handler(MessageHandler(filters=Filters.text, callback=handle_message))
However I want to also be able to send a URL to the bot from a POST request. i.e. use the telegram bot's API to send a message to itself so it can parse the link.
How can I send a POST request to my telegram bot and have it run handle_message() on the input?
It is technically impossible for bots to communicate with each other (and therefore with themselves).

Sending Discord Messages to external application

I am currently working on a desktop application and I want to get messages sent from Discord to this application. How should I do this?
I have used POST requests and webhooks to send messages TO Discord, but I have never taken messages from a channel and sent them somewhere else.
I know I can do something using on_message like this:
#bot.event
async def on_message(message):
message_content = message.content
## send message_content to external application
I just am confused on what to use/how to send the messages to the application itself. Keep in mind that this I'm making in Python 3.6.6

Categories

Resources