How to check the reply to a message guilded.py - python

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.

Related

Discord.py Private Messages Bot

In Discord.py how can I make my bot privately send messages to other people in a server. Like, if I want to message a person in the server who I have not friend requested yet, I can use this bot. I want it to use a slash command like
"/{user}{message}"
And the bot will display the message for them and make the user who it was sent to only see it.
How do I do this using discord.py?
You have to get the member and create a DM with them, then send whatever you want to the DM. See the following code:
member = discord.utils.get(ctx.guild.members, id = (member id)) # could also use client.get_user(ID)
dm = await member.create_dm()
await dm.send('this will be sent to the user!')

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.

Discord Bot waiting for multiple user input

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.

Get message content from reply in DM

I started making a little discord bot to give a key to people who request it. However, requirements changed and now I need to get a valid email from people who want one. I'm not sure how to get a reply in a DM.
I saw Discord.py get message from DM
But I don't really have client.get_user_info() or something?
bot = commands.Bot(command_prefix='!')
#bot.command(pass_context =True, no_pm=True, name='key', help="I give you a key. you're welcome", )
async def key_giver(ctx):
commandTime = str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
##check if you're PMing bot
elif isinstance (ctx.channel, discord.DMChannel):
print(ctx.message)
await ctx.author.send(keyArray[0])
else:
response = "Hello my friend. I give you a key for a game. This is my purpose. Please enter your email!"
##Send key via PM
await ctx.author.send(response)
Printing ctx.message is
<Message id=620538695124254720 channel=<DMChannel id=614377525417738240 recipient=<User id=605223566371192852 name='aon' discriminator='5906' bot=False>> type=<MessageType.default: 0> author=<User id=605223566371192852 name='aon' discriminator='5906' bot=False>>
I'm really not sure. I'm just stupid, please don't yell at me.
You can use Client.wait_for to wait for the message and use its results. You already have the User object (ctx.author), so you can get the channel to listen for from User.dm_channel. I'm re-using the message_check function from this previous answer to generate the check
# Send them a message in a DM
await ctx.author.send("Please give an email address")
# Wait for a response
response = await bot.wait_for('message', check=message_check(channel=ctx.author.dm_channel))

discord channel link in message

Using discord.py, I am making a bot to send users a direct message if a keyword of their choosing is mentioned.
Everything is working, except I just want to add the channel they were mentioned in to the message. Here is my code:
print("SENDING MESSAGE")
sender = '{0.author.name}'.format(message)
channel = message.channel.name
server = '{0.server}'.format(message)
await client.send_message(member, server+": #"+channel+": "+sender+": "+msg)
This results in a correct message being composed, but the #channel part of the message is not a clickable link as it would be if i typed it into the chat window myself. Is there a different object I should be feeding into the message?
In Discord: there is channel mention.
Try that way, do message.channel.mention instead of message.channel.name
it should able to link a channel in PM or everywhere.
Source: Discord Documentation

Categories