缺少 1 个必需的位置参数:“数字”

Shan Jameson

嗨,我在运行 asyncio 循环时遇到问题,它要求 missing 1 required positional argument: 'number'.

这是我正在使用的内容:

async def purge_modlog(ctx, number):
    tomorrow = datetime.now()+timedelta(days=1)
    midnight = datetime(year=tomorrow.year, month=tomorrow.month, 
    day=tomorrow.day, hour=20, minute=35, second=0)
    number = int(number)
    server = before.server
    db = fileIO(self.direct, "load")
    if not server.id in db:
        return
    channel = db[server.id]["Channel"]
    if number > 99 or number < 1:
        await ctx.send("I can only delete messages within a range of 1 - 99", delete_after=10)
    else:
        author = ctx.message.author
        authorID = author.id
        mgs = []
        number = int(number)
        channel = modlog
        async for x in bot.logs_from((channel), limit = int(number+1)):
            mgs.append(x)
            await asyncio.sleep((midnight - datetime.now()).seconds)
            print("Deleting modlog messages 14 day or older")
            await asyncio.sleep(5) 
            await delete_messages(mgs)
            await ctx.send('Success!', delete_after=4)
            await asyncio.sleep(86400) # Wait 24 hours




def check_folder():
    if not os.path.exists('data/modlogset'):
        print('Creating data/modlogset folder...')
        os.makedirs('data/modlogset')


def check_file():
    f = 'data/modlogset/settings.json'
    if not fileIO(f, 'check'):
        print('Creating default settings.json...')
        fileIO(f, 'save', {})


def setup(bot):
    check_folder()
    check_file()
    q = ModLog(bot)
    loop = asyncio.get_event_loop()
    loop.create_task(q.purge_modlog())
    bot.add_cog(q)

在def下循环事件def setup(bot):可以看到

loop = asyncio.get_event_loop()
loop.create_task(q.purge_modlog())

这应该循环事件(q.purge_modlog())我不确定我在这里做错了什么。我已经尝试过以下(q.purge_modlog(ctx, number))

line 686, in setup
loop.create_task(q.purge_modlog(ctx, number))
NameError: name 'ctx' is not defined

如果有人可以帮助我,那就太好了。添加这是一个模块。

用户10415595

我在这里纠正了一些错误。尝试通读有关清除消息的 discord.py 文档

 class ModLog:
    def __init__(self, bot):
        self.bot = bot


async def on_ready(self):
    await self.bot.wait_until_ready()
    for server in self.bot.servers:
        channel = self.bot.get_channel("channel ID here")
        if channel:
            self.bot.loop.create_task(self.modlog_purge(channel))

async def modlog_purge(self, channel):
    while True:
        now = datetime.utcnow()
        two_weeks_ago = now - timedelta(days=14)
        await self.bot.purge_from(channel, before=two_weeks_ago)
        await asyncio.sleep(86400)

def setup(bot):
    q = ModLog(bot)
    bot.add_cog(q)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

类型错误:button() 缺少 1 个必需的位置参数:“数字”

ArrayField缺少1个必需的位置参数

__init __()缺少1个必需的位置参数

缺少1个必需的位置参数:“ pk”

缺少1个必需的位置参数:“键”

python缺少1个必需的位置参数

channel()缺少1个必需的位置参数

AssertTrue 缺少 1 个必需的位置参数

缺少1个必需的位置参数:“循环”

缺少1个必需的位置参数:'self'

缺少1个必需的位置参数:“ msg”

缺少1个必需的位置参数

缺少 1 个必需的位置参数 dt

函数缺少 1 个必需的位置参数

缺少 1 个必需的位置参数 [Telebot]

method1()缺少1个必需的位置参数:“ self”

__init__() 缺少 1 个必需的位置参数:'self'

类型错误:post() 缺少 1 个必需的位置参数

类型错误:readData() 缺少 1 个必需的位置参数:“数据”

TypeError:detail()缺少1个必需的位置参数:“ request”

TypeError:predict()缺少1个必需的位置参数:“ params”

多处理,缺少 1 个必需的位置参数:“响应”

setUpClass()缺少1个必需的位置参数:“ cls”

TypeError:fit()缺少1个必需的位置参数:'y'

load_model()缺少1个必需的位置参数:“ filepath”

TypeError:append()缺少1个必需的位置参数:“ values”

django 模板标签缺少 1 个必需的位置参数:值

geopy TypeError:geocode()缺少1个必需的位置参数:“ query”

TypeError:setDocumentLocator()缺少1个必需的位置参数:“ locator”