Answer the question
In order to leave comments, you need to log in
Discord.py how to properly use @bot.check_once?
I have code:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
# Для удобства
@bot.event
async def on_ready():
print('Бот готов - Online...')
# Проверка
@bot.check_once
def whitelist(ctx):
if 1 > 0:
print('1>0')
# Тест
@bot.command()
async def test(ctx):
await ctx.send('Nice job!')
bot.run("TOKEN")
I need to make it so that when I write the !test command, the test should start, and if the test condition is true, then the !test command should continue executing. Answer the question
In order to leave comments, you need to log in
The function in the Bot.check_once decorator should return a "bool-alike" value (any value that will be interpreted as a bool. Roughly speaking, anything that supports bool(var)
).
For example:
WHITELIST = [990298932007060792]
@bot.check_once()
def whitelist(ctx):
print(f"Check is triggered: {ctx.author} executed {ctx.command}")
return ctx.author.id in WHITELIST # Если ID пользователя в указанном выше списке - вернет True
# В противном случае, результат будет оцениваться как False (функция без указания return возвращает None, а bool(None) == False
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question