異步 QQ 機器人框架_NoneBot


一、NoneBot使用

1) #監控發送的消息"群發"的事件
@on_command('send_msg', aliases=('群發',))
async def send_msg(session: CommandSession):
print("發送消息")
message_type=session.ctx['message_type']
user_id=session.ctx['user_id']
#判斷發送的消息是私聊的,並且發送的qq號碼是448113545
if message_type=='private' and user_id==448113545:
#獲取qq群的信息
group_list = await session.bot.get_group_list()
for group in group_list:
#對某個qq群進行發送信息
await session.bot.send_group_msg(group_id=group['group_id'],message='要群發的消息')
2)session.ctx
{'font': 6395088, 'message': [{'type': 'text', 'data': {'text': '33'}}], 'message_id': 36, 'message_type': 'private', 'post_type': 'message', 'raw_message': '33', 'self_id': 12345678, 'sender': {'age': 29, 'nickname': '美好', 'sex': 'unknown', 'user_id': 446789001}, 'sub_type': 'friend', 'time': 1578536478, 'user_id':446789001, 'to_me': True}
3.bot的使用
bot = nonebot.get_bot()
info = await bot.get_group_member_info(group_id=62234565, user_id=448112234)
await bot.send_group_msg(group_id=6227422, message='大家好~') # 發送群消息
# 監聽消息
bot = nonebot.get_bot()
# @bot.on_message('group') #監聽群組消息
@bot.on_message() #監聽所有消息
async def handle_group_message(ctx):
print("group ctx>>",ctx)
 



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM