Discord Bot waiting for multiple user input - python

Okay so, i have a bot that simply reacts to a single message.
user sends input.
bot sends output.
command done.
however i want the bot to for example ask the user something back
user sends input.
bot sends question: "are you sure you want to XXXXXX"
user sends 2. input.
bot sends output.
i am not sure tho how to make the bot wait for a second user message inside of one command.

You have to add a check before it.
def check(message, user):
return message.channel == ctx.message.channel and user.author == ctx.message.author
reply = await bot.wait_for('message', check=check)
Like this.

Related

How to check the reply to a message guilded.py

I'm making a command that requires checking what the user is going to reply with to a bot's message. Here's some sample code:
async def create_channel(message):
await message.reply("Reply to this with the channel name that you want to create")
How can I get the user's reply to this message? Have done the research, but didn't find it.

Delete messages on leave user, discord py

i want to create a discord bot using discord.py that when a user leave the bot will delete all the messages that user sent in all channels. I know to use the event handlers, but I don t have any idea on how to delete all messages from all channels of one user, I could just put the message id's in a dictionary, but maybe there is a better way.
And as reference is this bot: https://top.gg/bot/689790568154529792
async def on_member_remove(member):
for c in member.guild.channels:
await c.purge(limit=None, check=lambda m: m.author==member)

How do I make a bot respond to a specific reaction? Discord.py

I am trying to add a giveaway function to my discord bot but the reroll function I am trying to make does not work. When the giveaway ends it sends a message that says who won the giveaway. This is what I have defined as reroll. Then I make the bot wait and see if someone has added a 'x' reaction to this message. I am trying to make it so that if someone has added an 'x' reaction then it will redo the winner choice in the giveaway. I hope to also make this function repeat if multiple winners are invalid. But I am not exactly sure how I would make a bot respond specifically to a specific reaction on a message.
reroll = await channel.send(f'Congratulations! {winner.mention} won {prize}!')
if reroll.reactions == '❌':
winner2 = random.choice(users)
await channel.send(f'Congratulations! {winner2.mention} won {prize}!')
According to the discord documentation, we can check on_reaction_add(reaction, user).
Called when a message has a reaction added to it. Similar to
on_message_edit(), if the message is not found in the internal message
cache, then this event will not be called. Consider using
on_raw_reaction_add() instead.
With that you can basically check for the message
async def on_reaction_add(reaction, user):
if 'Congratulations!' in reaction.message.content and reaction.emoji == '❌':
# do stuff
You can access the Message being reacted via Reaction.message

Check if the message channel is in that category

Can someone help me? I'm trying to make a modmail every thing is working fine, user sends a DM, bot creates a channel under "category" and if someone message inside that "category" it will be delivered to the user via DM. However I get this annoying error every time someone replies inside that "category" or user DMs the bot. I'm trying to make a category check to only do something if it's the mod mail category. Thank you in advance!
Here's my code:
async def on_message(self, message):
if isinstance(message.channel, discord.DMChannel):
# User DM the bot and the bot will make a textchannel under "category" and will send his DMs there. #
if message.channel.category_id == 123456789101112:
if isinstance(message.channel, discord.TextChannel):
# Message the user who DMed the bot using the textchannel under "category", your replies will be sent to the user by the bot via DM. #
Everything is working, but I'm getting this error every time someone replies inside that textchannel "category" or user DMs the bot
Error:
if message.channel.category_id == 123456789101112:
AttributeError: 'DMChannel' object has no attribute 'category_id'
Your if-statement doesn't make much sense, you should first check for the type of the channel and then for it's category and compare it.
async def on_message(message):
# Checking if the channel is a dm or a text one
if isinstance(message.channel, discord.DMChannel):
# do your thing
elif isinstance(message.channel, discord.TextChannel):
if message.channel.category is not None:
if message.channel.category.id == your_id:
# do your thing
You should format your code properly.
Also you can check whether message.author.id is your bots id client.user.id or a user.
Read the documentation for further information.

How to receive a message from a certain user in discord, then wait for another certain user's reply, then send a custom message in python

I'm new to python and discord bots. I created a bot for my friend's server and I'm stuck on a certain event.
I want to be able to:
Wait for a certain user to send a random message
Wait for a certain user to respond to that message (if the someone else replies before the user I want, I want the code to stop running
Have the bot send a message
Here's my code, it may be incorrect, but I have never done something like this before. I would love it if someone replied with the full event function. Thanks!
#client.event
async def on_message(message):
if (message.author.id == "User who sends the first message"):
async def on_message(message):
if (message.author.id == "User who replies"):
await message.channel.send("Test worked")
print(on_message)
else:
return
else:
return
there is an inbuilt function for that
def check(user):
return user.channel.id == message.channel.id and user.author == message.author
reply = await bot.wait_for('message', check=check())

Categories