简体   繁体   English

在 Discord.py 中查看通道的消息历史记录

[英]Look through channel's message history in Discord.py

Given a specific channel's id, I want to look at all of the messages sent to check if it contains a string of text using the rewrite of discord.py.给定一个特定频道的 ID,我想查看所有发送的消息,以检查它是否包含使用 discord.py 重写的文本字符串。

import discord
from discord.ext import commands
token = "example token"
client = commands.Bot(command_prefix = '$')

Here is a simple example of using channel.history , depending on where you use the command, will search for all messages from that user for the past 100 messages, hopes this helps.这是一个使用channel.history的简单示例,根据您使用该命令的位置,将搜索该用户的所有消息以查找过去 100 条消息,希望对您有所帮助。 Feel free to change this to how you want, it will only currently look for the messages sent by the author of the command.随意将其更改为您想要的方式,它当前只会查找命令作者发送的消息。

@client.command()
async def history(ctx, member: discord.Member):
    counter = 0
    async for message in ctx.channel.history(limit = 100):
        if message.author == member:
            counter += 1

    await ctx.send(f'{member.mention} has sent {counter} messages in this {ctx.channel.mention}')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM