Discord.py bot:我如何使我的discord bot向我发送对用户在DM中使用的命令的响应,例如进行调查? [英] Discord.py bot: how would I make my discord bot send me responses to a command that users use in DMs e.g. for a survey?
问题描述
因此,我想让我的不和谐机器人拥有一个调查命令,如果用户说 #survey之类的东西,机器人将向他们发送问题。然后我要这样做,以便机器人将通过DM将响应(用户在DM中使用命令进行响应)发送给我?
我知道当他们在不和谐服务器中使用命令时如何使bot DM成为用户,但是它向我发送了响应部分,我可以
我是discord.py的新手,但是我已经仔细阅读了文档,然后才要求我检查是否可以找到任何相关的内容。 / p>
这也是我在该网站上遇到的第一个问题,我刚刚报名参加,请原谅,如果它写得不好。
预先感谢!
我认为您遇到问题的部分正在捕获响应。 discord.py
重载命令的 function(args,*,kwargs)
语法,以便在之后使用单个参数*
是消息其余部分的文本。
from discord.ext.commands import Bot
机器人= Bot('#')
my_user_id =<您的ID>
#激活开发人员模式后,您可以通过discord客户端获取ID。
@ bot.command(pass_context = True)
异步防御调查(ctx):
等待bot.send_message(ctx.message.author,您叫什么名字?)
@ bot.command(pass_context = True)
异步def响应(ctx,*,响应):
owner = await bot.get_user_info(my_user_id)
等待bot.send_message(所有者, {}响应:{}。format(ctx.message.author.name,响应))
bot.run( token)
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 make it so the response (where the user uses a command in DM to respond) will be sent to me via DM by the bot? Is this possible?
I know how to make the bot DM the user when they use the command in the discord server, but its the sending me the response part I can't get my head around.
I'm new to discord.py, but I have scanned through the documentation before asking this to check if i could find anything relevant.
Also this is my first ever question on this website, I just signed up so excuse this if it isn't written very well.
Thanks in advance!
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")
这篇关于Discord.py bot:我如何使我的discord bot向我发送对用户在DM中使用的命令的响应,例如进行调查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!