Discord.py AFK 命令
Posted
技术标签:
【中文标题】Discord.py AFK 命令【英文标题】:Discord.py AFK Command 【发布时间】:2021-01-22 23:02:24 【问题描述】:所以我和一个朋友已经研究了这个 AFK 代码,我们完成了除了提及之外的所有事情。该机器人应该检查提到的某人是否是 AFK,如果是,它应该发送一条消息说明他们为什么是 AFK。
@client.command()
async def afk(ctx, *, reason=None):
embed = discord.Embed(timestamp=ctx.message.created_at, color=0x00ffff)
embed.set_footer(text="Olympia Gaming")
post =
"member": ctx.message.author.id,
"reason": reason,
"date": str(ctx.message.created_at)
if reason == None:
collection.insert_one(post)
embed.add_field(name=f"ctx.author.name is now AFK", value="Reason: No reason specified.")
await ctx.send(embed=embed)
else:
collection.insert_one(post)
embed.add_field(name=f"ctx.author.name is now AFK", value=f"Reason: reason", inline=False)
await ctx.send(embed=embed)
@client.event
async def on_message(message):
embed = discord.Embed(timestamp=message.created_at, description="You have been removed from AFK.", color=0x00ffff)
results = collection.find("member": message.author.id)
for result in results:
collection.delete_one(result)
await message.channel.send(embed=embed)
上面的代码可以正常工作。
if message.mentions
results = collection.find("member": message.author.id)
for result in results:
collection.delete_one(result)
if message.content == result:
await message.channel.send(f"This person is currently AFK")
await client.process_commands(message)
我没有收到任何错误,但我也希望机器人在提到它们时显示它们被取消的原因。有人可以帮忙吗?
【问题讨论】:
【参考方案1】:这有点晚了,我不知道底部的 sn-p 是否有效,但如果有效,我们开始吧。
首先,我们需要将原因放入消息中。我们这样做,
#in the the chat box we need to add the to curly brackets
if message.mentions
results = collection.find("member": message.author.id)
for result in results:
collection.delete_one(result)
if message.content == result:
await message.channel.send(f"This person is currently AFK ")
await client.process_commands(message)
接下来,我们添加原因
if message.mentions
results = collection.find("member": message.author.id)
for result in results:
collection.delete_one(result)
if message.content == result:
await message.channel.send(f"This person is currently AFK reason")
await client.process_commands(message)
最后,定制!
if message.mentions
results = collection.find("member": message.author.id)
for result in results:
collection.delete_one(result)
if message.content == result:
await message.channel.send(f"This person is currently AFK, Reason? reason")
await client.process_commands(message)
就是这样,以后请参考discord.py 文档,甚至是python 文档!
Python 文档:https://docs.python.org/3/ Discord.py 文档:https://discordpy.readthedocs.io/en/latest/
希望对我有所帮助,请告诉我这是否已经修复以及任何问题!
【讨论】:
以上是关于Discord.py AFK 命令的主要内容,如果未能解决你的问题,请参考以下文章