【问题标题】:Discord.py message scraperDiscord.py 消息抓取工具
【发布时间】:2022-01-11 17:45:59
【问题描述】:

我正在尝试使用 discord.py 做一个消息 scrpper 机器人,但我遇到了问题。通过followign,我能够检测到我的帐户(组和dm)上收到的所有新消息,但是当我尝试获取该消息的内容时,它会返回一个空的str。它仅在我被标记或我是作者时返回消息内容。有谁知道我能做什么? 代码:

import discord
from discord.ext import commands

bot= commands.Bot(command_prefix='')

@bot.event
async def on_ready():
    print("ready")

@bot.event
async def on_message(message):
    print(message)
    print(message.clean_content)
    print(message.system_content)   
    print(message.content)


bot.run(token,bot=False)

如您所见,我尝试使用 clean_content、system_content 和 content 方法来获取消息内容。

谢谢

【问题讨论】:

  • 我假设您使用的是自我机器人? (bot.run(token,bot=False)) 这些不再受支持并且违反了 ToS。我怀疑你会在这个问题上得到任何帮助。

标签: python web-scraping discord discord.py bots


【解决方案1】:

首先,正如 Dominik 所说,不要在您的客户端上使用脚本。这不仅违反 TOS,而且如果被恶意使用,也会让其他用户非常恼火

其次,将消息存储在文本文件中:

@bot.event
async def on_message(message):
    with open("filename.txt", "a") as f:
        f.write(f"{message.author.name}: {message.content}\n")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-12
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 2022-08-05
    相关资源
    最近更新 更多