from discord.ext import tasks, commands
class MyCog(commands.Cog):
def __init__(self):
self.index = 0
self.printer.start()
def cog_unload(self):
self.printer.cancel()
@tasks.loop(seconds=5.0)
async def printer(self):
print(self.index)
self.index += 1
BASE = "https://discord.com/api/v9/"
TOKEN = "TOKEN_HERE"
def timeout_user(*, user_id: int, guild_id: int, until: int):
endpoint = f'guilds/{guild_id}/members/{user_id}'
headers = {"Authorization": f"Bot {TOKEN}"}
url = BASE + endpoint
timeout = (datetime.datetime.utcnow() + datetime.timedelta(minutes=time_in_mins)).isoformat()
json = {'communication_disabled_until': timeout}
session = requests.patch(url, json=json, headers=headers)
if session.status_code in range(200, 299):
return session.json()
else:
return print("Did not find any\n", session.status_code)
prefix = "!"
@bot.event
async def on_message(message):
# проверки на то, что сообщение в нужном канале, если это нужно
# if message.channel == {id канала}
if message.content.startswith(prefix):
await bot.process_commands(message)
else:
await message.delete()
for word in message.content.lower().split(" "):
if word in auto_moderation["bad_words"]:
await punish(...) # await message.guild.kick(user=message.author, reason="Bad words auto mod")