[英]How can you make a Discord bot (using discord.py) test for responses in dms?
I am working on a project for verification purposes, but I am having trouble finding any sources that point to how you can check for responses and their validity, as well as whether or not it is a response to the bot question.我正在开发一个用于验证目的的项目,但我无法找到任何指向您如何检查响应及其有效性以及它是否是对机器人问题的响应的来源。 Any suggestions or sources would be greatly appreciated.
任何建议或来源将不胜感激。
You can either use the on_message
event or wait_for
您可以使用
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")
Reference:参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.