【问题标题】:discord self bot acting like it cant read messages不和谐的自我机器人表现得像无法阅读消息
【发布时间】:2021-07-28 23:37:20
【问题描述】:

这是一个不和谐的自我机器人 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)

【问题讨论】:

标签: python discord


【解决方案1】:

由于某种原因,on_message 给出的消息对象中的.content.embeds 几天前停止了对不是自己发送的消息的自我机器人工作。

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

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

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

【讨论】:

    猜你喜欢
    • 2020-12-06
    • 2017-10-30
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 2020-05-31
    • 2020-04-21
    相关资源
    最近更新 更多