当前位置: 首页 > 知识库问答 >
问题:

不一致py-AFK命令

岑炯
2023-03-14

@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)  

我没有得到任何错误,但我也希望机器人显示他们是afk的原因,当他们提到。有人能帮忙吗?

共有1个答案

顾烨磊
2023-03-14

这有点晚了,我不知道底部片段是否有效,但如果有效,我们开始吧。

首先,我们需要把原因写进信息中。我们通过做来做到这一点,

#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)

就这样,以后请参考不和谐。py文档,甚至是python文档!

Python文档:https://docs.python.org/3/不一致py文档:https://discordpy.readthedocs.io/en/latest/

我希望我帮助,请告诉我,如果这是已经修复和关于任何问题!

 类似资料:
  • 我在我的discord机器人上遇到了一个问题。命令不起作用。我认为代码不是问题。除了命令外,一切都很完美。不和谐,如果我使用!在这里测试mytext,什么都不会发生。 提前谢谢你!

  • 我想发送消息,如果作者有角色,但如果我尝试此代码不工作(角色的id是正确的)。

  • 我一直在用discord编程一个机器人。py(重写分支)和我想添加一个ban命令。bot仍然没有禁止该成员,只是显示了一个错误: 它将禁止ping用户并确认它确实禁止了ping

  • 这是我的密码 我确实检查了这个discord bot和这个命令的每个其他cog(仅存在于此…)。为什么我总是犯这个错误? 我所做的:我注释掉了那段代码,再次启动bot,它给了我相同的错误,但是命令名不同,我注释了所有显示的命令11次(尽管它们只在一个地方定义)。但我总是犯这样的错误! 这个机器人有超过240个命令,它与问题有关吗? 我能做什么?

  • 我得到了一个unban命令代码,在控制台中出现以下错误: (节点:9348)未处理的PromisejectionWarning:TypeError:无法读取未定义的at对象的属性“member”。在客户端执行(C:\Users\19nik\Documents\GitHub\bot project\commands\unban.js:9:22)。(C:\Users\19nik\Documents\G

  • 如果我执行类似于它工作正常。 但是,我找不到一种方法使其适用于ping。我尝试了机器人ID和名称。我的机器人ID代码: 有人能帮忙吗?