type(row[0])
, скорее всего вы храните/БД возвращает ID в виде строки, get_role
принимает ID в виде int
get_channel
принимает на вход аргумент типа int
- ID канала.pass_context
в discord.py не существует уже два года.@bot.command()
async def cmd(ctx, channel: discord.TextChannel, *, msg: str):
"""Send msg to channel"""
await channel.send(msg)
user = discord.utils.get(bot.users, name="Name", discriminator="1234")
user_id = user.id
role = bot.get_guild(940108264659634772).get_role(695290124871312928)
for member in role.members:
print(str(member))
from asyncio import sleep
from discord.ext import tasks
...
@tasks.loop(seconds=30)
async def call_work(channel):
await channel.send("p!work")
@tasks.loop(minutes=10)
async def call_trivia(channel):
await channel.send("p!trivia hard")
@client.event
async def on_ready():
print("We are ready after socket connect")
command_tasks = [call_work, call_trivia]
for task in command_tasks:
if not task.is_running(): # on_ready может запускаться более чем один раз https://discordpy.readthedocs.io/en/stable/api.html#discord.on_ready
print(f"Starting task {task.__name__}")
task.start(client.get_channel(CHANNEL_ID))
for member in role.members:
await member.send(message)
humanize
: https://pypi.org/project/humanize/In [1]: import humanize
In [2]: import datetime as dt
In [3]: humanize.naturalday(dt.datetime.now() - dt.timedelta(days=1))
Out[3]: 'yesterday'
In [4]: humanize.naturalday(dt.datetime.now() + dt.timedelta(days=1))
Out[4]: 'tomorrow'
In [5]: humanize.naturalday(dt.datetime.now())
Out[5]: 'today'
In [6]: humanize.i18n.activate("ru_RU")
Out[6]: <gettext.GNUTranslations at 0x5a35478>
In [7]: humanize.naturalday(dt.datetime.now() - dt.timedelta(days=1))
Out[7]: 'вчера'
In [8]: humanize.naturalday(dt.datetime.now() + dt.timedelta(days=1))
Out[8]: 'завтра'
In [9]: humanize.naturalday(dt.datetime.now())
Out[9]: 'сегодня'