discord bot 发送私信实现消息提醒

discord bot 发送私信实现消息提醒

通过用户的discord创建用户的私信通道,bot机器人向用户的discord发过期提醒

在这里插入代import discord
from discord.ext import commands
# import yaml
import random
from datetime import datetime as dt
from discord.ext import tasks as discordTasks
from redis_util import RedisUtil
rs = RedisUtil()
TOKEN = "你bot的token"
client = discord.Client()
# set command prefix
client = commands.Bot(command_prefix='dmb ')
import json
async def overdue_user():
    """
    过期用户
    :return:
    """
    embed = discord.Embed(
        title='标题',
        color=0xF1C40F,
        url='链接'
    )
    embed.description='''
    亲,您的账号即将到期,请及时续费,到期后将无法登陆,且不会统计数据,由此造成的数据丢失,淘账通概不负责。
Your account number of taozhangtong is about to expire. Please renew it in time. After the expiration, 
you will not be able to log in, and there will be no statistical data. Taozhangtong will not be responsible for the loss of data 
    '''
    
    data = rs.get_str_dict('overdue_user_discord') # 从redis里获取过期账户的discord用户id
    print(data)
    if data:
        result = eval(data)
        for i in result:
            user = await client.fetch_user(int(i['discord_id'])) # 通过用户id获取user对象
            await user.create_dm()  # 创建私信通道
            await user.dm_channel.send(embed=embed) # 向用户发送私信
    	rs.dele_all_redis('overdue_user_discord') # 删除缓存


# loop for sending message
@discordTasks.loop(seconds=10)
async def messageDaily(): 
    await overdue_user()


# TODO: save to config file
# TODO: better help function

messageDaily.start()
client.run(TOKEN)
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值