【问题标题】:Discord Python - How to make the BOT search for a message?Discord Python - 如何让 BOT 搜索消息?
【发布时间】:2019-03-23 16:41:43
【问题描述】:

有谁知道如何让 BOT 在特定服务器上的特定频道中查找特定消息? 如果 BOT 找到了,他会做 ssm,否则他会做 ssm 否则。 我现在有这个:

@bot.command(pass_context=True)
async def command(ctx):
    search = discord.utils.get(bot.get_message, message = 'MESSAGE', channel = bot.get_channel(id = 'CHANNEL ID'))
    if not search == None:
        await bot.say("SSM")
    else:
        await bot.say("SSM ELSE")

它说错误...

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    这里我使用logs_from 来读取带有ID 的频道消息,查找包含调用该命令的服务器ID 的消息。

    from discord import NotFound
    
    @bot.command(pass_context=True, name="command")
    async def _command(ctx):
        channel_id = "123"
        channel = bot.get_channel(channel_id)
        if not channel:
            await bot.say("Error: Could not resolve controller channel")
            return
        server_id = ctx.message.server.id
        async for message in bot.logs_from(channel, limit=500):
            if server_id in message.content:
                await bot.say("SSM")
                return
        await bot.say("SSM ELSE")
    

    【讨论】:

    • 我不明白你想做什么。你想得到什么信息?你对它了解多少?
    • 您可以将服务器 ID 存储在其他地方吗?将它们与您的机器人一起存储在文本文件中会更有意义
    猜你喜欢
    • 2023-04-02
    • 2021-03-27
    • 2018-05-03
    • 2021-10-30
    • 2021-09-17
    • 2019-06-07
    • 2018-07-07
    • 2020-05-11
    • 2019-07-04
    相关资源
    最近更新 更多