Releases: nonebot/adapter-discord
Releases · nonebot/adapter-discord
v0.1.0beta3
What's Changed
- Fix: 斜杠命令Option类型启用自动转换,修复纯文本消息误转义问题 by @jks15satoshi in #6
New Contributors
- @jks15satoshi made their first contribution in #6
Full Changelog: v0.1.0beta2...v0.1.0beta3
v0.1.0beta2
Feature
GuildFeature
补充SOUNDBOARD
类型- 修改默认
Indents
,需特权的权限默认改为 False
Document
README
添加 logo 和斜杠命令插件示例
Full Changelog: v0.1.0beta1...v0.1.0beta2
v0.1.0-beta.1
What's Changed
- Discord 适配器预发布版本,已完成绝大部分内容
Example
需要在.env.*
配置文件写入:
DISCORD_BOTS='
[
{
"id": "your_bot_id",
"token": "your_bot_token",
"application_commands": {"*": ["*"]}
}
]
'
# application_commands的{"*": ["*"]}代表将全部应用注册为全局应用命令
# {"admin": ["123", "456"]}则代表将admin命令注册为123、456服务器的局部命令,其余命令不注册
常见的 nonebot 插件写法:
from nonebot import on_command
from nonebot.adapters.discord import MessageCreateEvent
from nonebot.rule import to_me
matcher = on_command("hello", rule=to_me())
@matcher.handle()
async def hello_handler(event: MessageCreateEvent):
await matcher.send("Hello, world!", at_sender=True)
Discord 的斜杠命令用法:
import asyncio
from typing import Optional
from nonebot.adapters.discord.api import (
IntegerOption,
NumberOption,
StringOption,
SubCommandOption,
User,
UserOption,
)
from nonebot.adapters.discord.commands import (
CommandOption,
on_slash_command,
)
matcher = on_slash_command(
name="permission",
description="权限管理",
options=[
SubCommandOption(
name="add",
description="添加",
options=[
StringOption(
name="plugin",
description="插件名",
required=True,
),
IntegerOption(
name="priority",
description="优先级",
required=False,
),
],
),
SubCommandOption(
name="remove",
description="移除",
options=[
StringOption(name="plugin", description="插件名", required=True),
NumberOption(name="time", description="时长", required=False),
],
),
SubCommandOption(
name="ban",
description="禁用",
options=[
UserOption(name="user", description="用户", required=False),
],
),
],
)
@matcher.handle_sub_command("add")
async def handle_user_add(
plugin: CommandOption[str], priority: CommandOption[Optional[int]]
):
await matcher.send_deferred_response()
await asyncio.sleep(2)
await matcher.edit_response(f"你添加了插件 {plugin},优先级 {priority}")
await asyncio.sleep(2)
fm = await matcher.send_followup_msg(
f"你添加了插件 {plugin},优先级 {priority} (新消息)"
)
await asyncio.sleep(2)
await matcher.edit_followup_msg(
fm.id, f"你添加了插件 {plugin},优先级 {priority} (新消息修改后)"
)
@matcher.handle_sub_command("remove")
async def handle_user_remove(
plugin: CommandOption[str], time: CommandOption[Optional[float]]
):
await matcher.send(f"你移除了插件 {plugin},时长 {time}")
@matcher.handle_sub_command("ban")
async def handle_admin_ban(user: CommandOption[User]):
await matcher.finish(f"你禁用了用户 {user.username}")
New Contributors
- @CMHopeSunshine made their first contribution in #1
Full Changelog: https://github.com/nonebot/adapter-discord/commits