So, I want to make my discord bot have a command for a survey where if the user says something like \"#survey\" then the bot will DM them with the question. Then I want to m
@client.event
async def on_message(message):
if message.channel.is_private:
#If any of the users DM the bot, the bot will send you the message in your DMS
owner = client.get_member("id_to_send")
await client.send_message(owner,f"{message.author}": {message.content})
await client.process_commands(message)
@client.command(pass_context=True)
async def survey(ctx):
await client.send_message(ctx.message.author,"The question you want to ask.")
This could work fine :-)
I assume the part you're having trouble with is capturing the response. discord.py
overloads the function(args, *, kwargs) syntax for commands, so that a single argument after the *
is the text of the rest of the message.
from discord.ext.commands import Bot
bot = Bot('#')
my_user_id = "<Your ID>"
# You can get your id through the discord client, after activating developer mode.
@bot.command(pass_context=True)
async def survey(ctx):
await bot.send_message(ctx.message.author, "What's your name?")
@bot.command(pass_context=True)
async def respond(ctx, *, response):
owner = await bot.get_user_info(my_user_id)
await bot.send_message(owner, "{} responded: {}".format(ctx.message.author.name, response))
bot.run("token")