You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

vkbottle使用BaseStateGroup遇弃用警告,寻求解决方案

解决VKBottle中BaseStateGroup弃用警告问题

问题代码

我编写了以下代码尝试创建状态:

from vkbottle.bot import Bot, Message
from vkbottle import Keyboard, KeyboardButtonColor, Text
from vkbottle_types import BaseStateGroup
class SuperStates(BaseStateGroup):
  NAME = 0


@bot.on.message(state=SuperStates.NAME)  # StateRule(SuperStates.AWKWARD_STATE)
async def awkward_handler(message: Message):
   await message.answer("oi awkward")

@bot.on.message(lev="/die")
async def die_handler(message: Message):
   await bot.state_dispenser.set(message.peer_id, SuperStates.NAME)
   return "ok"

错误信息

运行后出现如下警告:

raise DeprecationWarning(
DeprecationWarning: BaseStateGroup from vkbottle_types is deprecated and will be removed in future releases, use vkbottle.BaseStateGroup instead

解决方法

这个警告的含义很直接:vkbottle_types模块中的BaseStateGroup已被弃用,后续版本会彻底移除,需要改用vkbottle核心包中的BaseStateGroup。

只需修改导入语句:

  • 将from vkbottle_types import BaseStateGroup替换为from vkbottle import BaseStateGroup

修改后的完整代码:

from vkbottle.bot import Bot, Message
from vkbottle import Keyboard, KeyboardButtonColor, Text, BaseStateGroup
class SuperStates(BaseStateGroup):
  NAME = 0


@bot.on.message(state=SuperStates.NAME)
async def awkward_handler(message: Message):
   await message.answer("oi awkward")

@bot.on.message(lev="/die")
async def die_handler(message: Message):
   await bot.state_dispenser.set(message.peer_id, SuperStates.NAME)
   return "ok"

保存代码后重新运行,警告就会消失。

内容的提问来源于stack exchange,提问作者Kirill Shishkov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 11:10:12