Discord self bot 表现得好像无法读取消息

时间:2021-05-06 15:56:10

标签: python discord

这是一个用于不和谐的自机器人 mudae 狙击手

我前一段时间(比如 2 个月前)做了它然后停止使用它我决定再次使用它但它不起作用

它登录但它没有反应或打印它应该的消息 它就像它甚至没有看到消息

没有任何错误信息

老实说不知道我错过了什么

导入为:from discord.ext import commands import discord, json, asyncio, re, os

代码:

from imports import *

try:
    with open("config.json", "x"): pass
    config = {"token": input("Enter discord token: "), "min": int(input("Enter minimum amount of kakera: "))}
    with open("config.json", "w") as configFile:
        configFile.write(json.dumps(config))
except:
    with open("config.json", "r") as configFile:
        config = json.loads(configFile.read())

bot = commands.Bot(">", self_bot=True)

@bot.event
async def on_connect():
    os.system("cls")
    print(f"Logged in as: {bot.user}\n")

@bot.event
async def on_message(message):
    if message.author.id == 488711695640821760 and message.embeds:
        if "wished" in message.content.lower():
            try:
                kakera = int(re.findall(r"\*\*([0-9]+)\*\*", message.embeds[0].description)[0])
                if kakera < config["min"]:
                    print(kakera, "is less than", config["min"])
                    return
            except Exception as e:
                return
            fails = 0
            print(f"Claiming {message.embeds[0].title} in {message.channel.guild.name}")
            while True:
                try:
                    await message.add_reaction(message.reactions[0])
                    return
                except Exception as e:
                    print(e)
                    if fails > 3:
                        break
                    await asyncio.sleep(0.1)
                    fails += 1
            print("Failed to claim")

bot.run(config["token"], bot=False)

1 个答案:

答案 0 :(得分:1)

出于某种原因,来自 .content 提供的消息对象的 .embedson_message 在几天前停止工作,用于非您自己发送的消息的自助机器人。

但是 channel.history 的消息可以正常工作。

一种解决方法是改为使用限制为 1

@bot.event
async def on_message(message):
    async for message in message.channel.history(limit=1):
        print(message.content)