I have a telegram bot and I use the python-telegram-bot library. what I try to is when user for example press on trade button I want to ask him about some deatails so I have to wait for the user input then process the answer
I have this this CmmandHandler which working well but its work just with command
ConversationHandler(
entry_points=[commandhandler('trade',trade)],
states={
NAME_adduser: [MessageHandler(Filters.text, callback=binance)],
},
fallbacks=[CommandHandler('quit', quit)]
)
I search alot but found nothing about use InlineKeyboardButton value as a command
Related
I'm trying to have my bot keep track of items that are being spawned by another bot (Mee6).
The following code gives me a None output.
#client.event
async def on_message(message:discord.Message):
if message.author.bot:
print(message.content)
The command the other bot is responding to is:
/spawn-item member={member} item={item} amount={amount}
I would like to retrieve these values.
Any help would be welcome!
Your code doesn't work, because you want to get an interaction, not a message.
Unfortunately, there is no way to get the interaction of another client. At most you can have a MessageInteraction, which gives you the name of the command used.
But in your case you can make it work since MEE6 still accepts the old command format. If you use the prefix of MEE6 instead of the / command, your code should work (with a bit of reworking: you would need to look at the message right before MEE6's response, or look if a message starts with the MEE6's prefix)
I'm trying to send message with inline keyboard:
await user_bot.send_message(
user_id, "This is a InlineKeyboardMarkup example",
reply_markup=InlineKeyboardMarkup([[
InlineKeyboardButton('Смотреть онлайн!', url='http://f1.ikino.site/index.php?do=search', callback_data='watch online'),
InlineKeyboardButton('Поиск фильмов!', url='http://f1.ikino.site/index.php?do=search',
callback_data='search films',)
]])
)
But it do not wokring!!! Can anybody help me?
Message was send, but without inlineKeyboard
Assuming you're logged in as a user, seeing your user_bot variable.
Users cannot attach a Keyboard (Reply or Inline). Use a normal Bot.
Hello Stackoverflow Community,
I wanted to write a Discord-Bot in Python, which should solve simple Mathquestions, like: "Whats 55+40?". The Questions are asked from another bot and the structure of the Question is everytime the same. I wrote a Calculator and it works and i just need the input from a private message(not a server). I do not need to show any code, because I dont have some and I need to start at the described situation to save the messages in a variable, so my Question is:
How can I import private messages from Discord, to save them in a normal variable, like x?
I use Sublime Text
Thanks for answers!
Looking at the comments of the question it is clear that you don't have any code for a bot yet. Look at this quickstart guide to set up a bot. Once set up, all messages typed to the bot (also DM messages) will trigger the on_message event. You can then save the contents of the message into a variable like so
#client.event
async def on_message(message):
messageContent = message.content
i assume what you mean is waiting for a user to reply to a certain message from the bot, you can get your bot to private message someone by doing something like this:
user = ctx.author
await user.send("Hello, world!")
now, for your bot waiting for a reply for your user, in your code, you will need a check just to make sure only the bot is waiting for a message from the specific person (even in dms) by creating a check function:
def check(m):
return m.author.id == ctx.author.id
then after using user.send to send a message, or an embed, add
message = await bot.wait_for('message', check=check, timeout=120)
which means the bot waits until the user sends their answer (waits 120 seconds in this example)
then, to get the content of the message you just want to do make a variable called content or answer and set it to message.content ( content = message.content )
I'm trying to find a way to program my bot to clear a specific amount of messages in a channel. However, I do not know how to get my bot to run it's code based on the user's input data. For example, let's say I'm a user who wants to clear a specific amount of messages, like let's say 15 messages. I want my bot to then clear 15 messages exactly, no more, no less. How do I do that?
if message.content == "{clear":
await message.channel.send("Okay")
await message.channel.send("How many messages should I clear my dear sir?")
This is legit all I got lmao. I'm sorry that I'm such a disappointment to this community ;(
Using a on_message event, you'd have to use the startswith mehtod and create a amount variable which takes your message content without {clear as a value:
if message.content.startswith("{clear"):
amount = int(message.content[7:])
await message.channel.purge(limit=amount+1)
However, I don't recommend using on_message events to create commands. You could use the commands framework of discord.py. It will be much easier for you to create commands.
A quick example:
from discord.ext import commands
bot = commands.Bot(command_prefix='{')
#bot.event
async def on_ready():
print("Bot's ready to go")
#bot.command(name="clear")
async def clear(ctx, amount: int):
await ctx.channel.purge(limit=amount+1)
bot.run("Your token")
ctx will allow you to access the message author, channel, guild, ... and will allow you to call methods such as send, ...
This is my first discord bot I have created, and it is for an idea that is complicated but I find as fun. I was wanting to create a discord bot that can send private messages to random users at a certain time (in my case, once every 24 hours). Is there a way to code this? I am using Node.js/nodemon to run the code. I already have the bot running and online, I just need a way to do what I was hoping to accomplish! Thank you to anyone who could help me out with this!
I would do setTimeout of some sort if you have your bot hosted 24/7.... If not I would find some sort of npm package that shows the time and then do
if(npmpackagetime == 'Whatever time you want here') return user.send('Your message here')
And if you want to chose a random user, make an array of all the guild's users and then do let newUser = Math.floor(Math.random() * arrayName.length); and then newUser.send('Your message here');