Discord Python-如何使BOT搜索消息?

时间:2018-10-18 19:40:31

标签: python discord discord.py

有人知道如何使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")

说错误...

1 个答案:

答案 0 :(得分:0)

在这里,我使用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")