discord py отправка сообщений в канал 24 часа
Нужно чтобы бот каждые сутки отправлял какое-либо сообщение в определенный канал.
Код для изменения:
from discord.ext import commands
bot = commands.Bot(command_prefix='.')
@bot.event
async def on_ready():
print('Bot logged as {}'.format(bot.user))
# Ваше решение
@bot.event
async def on_message(ctx):
message = get_message()
await bot.get_channel(********).send(message')
token = '*********************'
bot.run(token)
Ответы (2 шт):
Автор решения: xZartsust
→ Ссылка
Попробуйте так:
from discord.ext import commands
import asyncio
bot = commands.Bot(command_prefix='.')
@bot.event
async def on_ready():
print('Bot logged as {}'.format(bot.user))
@bot.event
async def on_message(ctx):
message = get_message()
await bot.get_channel(********).send(message)
await asyncio.sleep(86400) # 24 часов это 86400 секунд
await bot.get_channel(********).send(message)
token = '*********************'
bot.run(token)
Автор решения: HelloWorld
→ Ссылка
import asyncio
from discord.ext import commands
bot = commands.Bot(command_prefix='.')
async def background_task():
time = 86400
await asyncio.sleep(time)
message = get_message()
await bot.get_channel(********).send(message)
@bot.event
async def on_ready():
print('Bot logged as {}'.format(bot.user))
@bot.event
async def on_message(ctx):
pass
token = '*********************'
bot.loop.create_task(background_task())
bot.run(token)