从随机日期发送消息

时间:2021-03-12 01:24:32

标签: python-3.x discord.py python-datetime

我试图让我的不和谐机器人从服务器历史记录中的随机日期发送一条消息,但 around 参数似乎无法正常工作

def random_date():
    d1 = date(year=2020, month=3,day=16)
    d2= date.today()
    delta = d2 - d1
    int_delta = delta.days
    random_number_of_days = random.randrange(int_delta)
    ran = random_number_of_days
    global day
    day = d1 + timedelta(ran)
    # en = d1 + timedelta(ran + 1)
    return day


    @commands.command(name='quote')
    async def quote(self,message):
        day = random_date()
        messages = await message.channel.history(around=day).flatten()
        msg = random.choice(messages)
        embed = discord.Embed(description=f'{msg.content}' , color=message.author.color, timestamp=msg.created_at)
        embed.set_author(name=f"{msg.author.name}#{msg.author.discriminator}", icon_url=msg.author.avatar_url)
        embed.add_field(name = 'Source' , value = f"[Jump]({msg.jump_url})")
        embed.set_footer(text=f"Found in : #{message.channel.name}")
        await message.channel.send(embed=embed) 

1 个答案:

答案 0 :(得分:0)