代码:
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)