muteGuildMember怎么用啊我丢

代码:

import { Context, Schema } from 'koishi'

export const name = 'banme'

export interface Config {}

export const Config: Schema<Config> = Schema.object({})

export function apply(ctx: Context,config: Config) {
  ctx.command('banme', 'Ban yourself for a random time').action(async ({ session }) => {
    // 随机生成一个整数时间,单位为毫秒,最大29天,最小1分钟
    const banTime = Math.floor(Math.random() * 2505600000 + 60000)
    ctx.logger('banme').info(`Banned ${session.userId} for ${banTime}ms`)
    await session.bot.muteGuildMember(session.guildId, session.userId, banTime)
    return `已禁言 ${banTime} 秒`
  })
}

log(platform: QQ):

2023-08-15 17:30:44 [I] banme Banned 3327930436 for 1353294796ms
2023-08-15 17:30:44 [W] command banme 
                        Error: Error with request set_group_ban, args: {"group_id":"159184560","user_id":"3327930436","duration":1353294.796}, retcode: 100
                            at _Internal._get (/home/fantastic-spoon/node_modules/@satorijs/adapter-onebot/src/types.ts:558:11)
                            at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
                            at _Internal._Internal.<computed> (/home/fantastic-spoon/node_modules/@satorijs/adapter-onebot/src/types.ts:584:20)
                            at _Command.<anonymous> (/home/fantastic-spoon/external/banme/src/index.ts:14:5)
                            at Array.<anonymous> (/home/fantastic-spoon/node_modules/@koishijs/core/src/command/command.ts:279:14)
                            at _Command.execute (/home/fantastic-spoon/node_modules/@koishijs/core/src/command/command.ts:295:22)
                            at <anonymous> (/home/fantastic-spoon/node_modules/@koishijs/core/src/session.ts:401:22)
                            at _Session.withScope (/home/fantastic-spoon/node_modules/@koishijs/core/src/session.ts:268:22)
                            at next (/home/fantastic-spoon/node_modules/@koishijs/core/src/middleware.ts:320:16)
                            at next (/home/fantastic-spoon/node_modules/@koishijs/core/src/middleware.ts:320:16)

log(platform: Telegram):

2023-08-15 17:32:18 [I] banme Banned 5361485758 for 2316669239ms
2023-08-15 17:32:18 [W] command banme 
                        TypeError: session.bot.muteGuildMember is not a function
                            at _Command.<anonymous> (/home/fantastic-spoon/external/banme/src/index.ts:14:23)
                            at Array.<anonymous> (/home/fantastic-spoon/node_modules/@koishijs/core/src/command/command.ts:279:27)
                            at Object.argv.next (/home/fantastic-spoon/node_modules/@koishijs/core/src/command/command.ts:291:14)
                            at _Command.execute (/home/fantastic-spoon/node_modules/@koishijs/core/src/command/command.ts:295:33)
                            at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
                            at <anonymous> (/home/fantastic-spoon/node_modules/@koishijs/core/src/session.ts:401:22)
                            at _Session.withScope (/home/fantastic-spoon/node_modules/@koishijs/core/src/session.ts:268:22)
                            at next (/home/fantastic-spoon/node_modules/@koishijs/core/src/middleware.ts:320:16)
                            at next (/home/fantastic-spoon/node_modules/@koishijs/core/src/middleware.ts:320:16)
                            at _Processor._handleMessage (/home/fantastic-spoon/node_modules/@koishijs/core/src/middleware.ts:331:22)
1 个赞

(Koishi 提供一个随机数工具

import { Random } from 'koishi'
2 个赞

看起来是适配器实现问题

Telegram Adapter

Onebot Adapter
Onebot Adapter setGroupBan Impl

2 个赞


虽然但是好像还是有怪怪问题
以及muteGuildMember的duration的单位是毫秒吧w

1 个赞

你的 .02 究竟是怎么弄出来的

1 个赞

我翻了下onebot的代码和我的日志,我随机生成的数字为28455020,然后onebot的代码中似乎在禁言时又额外对duration进行了/1000的操作,导致原本的整数变成浮点数

以及我重新修改代码使得duration变为整数后,问题依旧存在:

1 个赞

那就是确实有报错了,打开 onebot 的调试日志看一下日志吧。

OneBot的调试日志咋开(文档没找到

1 个赞

有两种方法:


啊?

1 个赞


似乎不是这样(?

image

1 个赞

1 个赞

中文看不懂吗(

1 个赞

但是我已经给机器人群主了(
image
image

1 个赞