Python 3.x Discord.py bot:我如何让我的Discord bot向用户在DMs中使用的命令(例如用于调查)发送响应?

Python 3.x Discord.py bot:我如何让我的Discord bot向用户在DMs中使用的命令(例如用于调查)发送响应?,python-3.x,discord.py,Python 3.x,Discord.py,因此,我想让我的discord机器人有一个用于调查的命令,如果用户说“调查”之类的话,机器人就会用这个问题对他们进行DM。然后我想让响应(用户使用DM中的命令进行响应)通过DM由bot发送给我?这可能吗 我知道当bot DM在discord服务器中使用命令时,如何使其成为用户,但这是向我发送响应部分,我无法理解 我是discord.py的新手,但在询问此问题之前,我已经浏览了文档,以检查是否可以找到任何相关内容 这也是我在这个网站上的第一个问题,我刚刚注册,所以如果写得不好,请原谅 提前谢谢 我

因此,我想让我的discord机器人有一个用于调查的命令,如果用户说“调查”之类的话,机器人就会用这个问题对他们进行DM。然后我想让响应(用户使用DM中的命令进行响应)通过DM由bot发送给我?这可能吗

我知道当bot DM在discord服务器中使用命令时,如何使其成为用户,但这是向我发送响应部分,我无法理解

我是discord.py的新手,但在询问此问题之前,我已经浏览了文档,以检查是否可以找到任何相关内容

这也是我在这个网站上的第一个问题,我刚刚注册,所以如果写得不好,请原谅


提前谢谢

我认为您遇到的问题是捕获响应
discord.py
命令语法,因此
*
后面的单个参数是消息其余部分的文本

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")
从discord.ext.commands导入Bot
bot=bot(“#”)
my_user_id=“”
#激活开发者模式后,您可以通过discord客户端获取id。
@命令(pass\u context=True)
异步def调查(ctx):
等待机器人发送消息(ctx.message.author,“你叫什么名字?”)
@命令(pass\u context=True)
异步def响应(ctx,*,响应):
所有者=等待机器人。获取用户信息(我的用户id)
等待bot.send_消息(所有者,“{}响应:{}”。格式(ctx.message.author.name,响应))
bot.run(“令牌”)

这可以很好地工作:-)

谢谢!我现在明白了。
@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.")