python - 如何让 Discord 机器人(使用 discord.py)测试 dms 中的响应?
问题描述
我正在开发一个用于验证目的的项目,但我无法找到任何指向您如何检查响应及其有效性以及它是否是对机器人问题的响应的来源。任何建议或来源将不胜感激。
解决方案
您可以使用该on_message
事件或wait_for
@bot.event
async def on_message(message):
# Checking if the type of the channel is `discord.DMChannel`
if isinstance(message.channel, discord.DMChannel):
await message.channel.send("Responding in dm's")
@bot.command()
async def command(ctx):
def check(message):
# Checking if the author of the message is the same as the author of the command
# And if the channel is a `discord.DMChannel` instance
return message.author == ctx.author and isinstance(message.channel, discord.DMChannel)
await ctx.author.send("Waiting for a reply in dm's")
message = await bot.wait_for('message', check=check)
await ctx.author.send("Responding in dm's")
参考:
推荐阅读
- html - 如何使用 queryselectorall 从网站抓取特定数据到 Excel
- reactjs - 为什么大括号内的内容没有在 React.js 中渲染
- google-sheets - 如何使这 3 个表格在 Google Sheets 上相互通信?
- macos - 如何添加 MacOS 服务以将多个选定图像从消息传输到下载文件夹?
- android - Delphi FireMonkey在android系统上强制引发触摸事件
- oracle - 我在 Amazon RDS 中有哪些选项可以使用“fixed_date”?
- python - 在熊猫数据框中运行折扣价
- php - 如何在 PHP 中使用 stacktrace 保存代码行?
- r - 用 R 重塑表格
- react-native - tensorflow-models/mobilenet 在设备离线时不工作