簡體   English   中英

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

[英]Discord Python - How to make the BOT search for a message?

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

它說錯誤...

在這里,我使用logs_from來通讀帶有id的channel消息,尋找一條消息,其中包含在其中調用命令的服務器的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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM