इसलिए मैंने इस बॉट के लिए कोड लिखा और मैं चाहता हूं कि यह दो काम करे:
- १५ मिनट के लिए कूलडाउन करें
- एक आदेश है जो केवल शुक्रवार को काम करता है।
मैं कोडिंग के लिए नया हूँ इसलिए कलह दस्तावेज़ीकरण ने मदद नहीं की।
मेरे आयात:
import discord, asyncio, time, discord.guild, random, os, youtube_dl
import os
import asyncio
import math
import random
import youtube_dl
import datetime
import json
from discord.ext import commands, tasks
from discord.ext.commands import Bot, guild_only
from itertools import cycle
15 मिनट कूल डाउन के लिए कोड:
@client.command()
async def beg(ctx):
await open_account(ctx.author)
users = await get_bank_data()
user = ctx.author
earn = random.randrange(6900)
await ctx.send(f'Someone gave you {earn} coins!')
users[str(user.id)]["wallet"] += earn
with open('main code\economy.json', 'w') as f:
json.dump(users,f)
केवल शुक्रवार को काम करने वाले आदेश के लिए कोड:
@client.command()
async def friday(ctx):
vid = '<URL>'
await ctx.send(vid)
1 उत्तर
१५ मिनट का कूलडाउन
@commands का उपयोग करें। कूलडाउन ()
@client.command()
@commands.cooldown(1, 900, commands.BucketType.user) # 15 minutes is 900 seconds
async def command_with_cooldown(ctx):
... # code
@command_with_cooldown.error
async def cooldown_error_handler(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send("You can only use this command once every 15 minutes!")
केवल शुक्रवार
datetime.datetime.today().weekday()का उपयोग करें ए>
import datetime
@client.command()
async def friday_command(ctx):
if datetime.datetime.today().weekday() == 4: # 0 is monday, 6 is sunday
... # code
else:
await ctx.send("You can only use this command on fridays!")
संबंधित सवाल
नए सवाल
python
पायथन एक बहु-प्रतिमान है, गतिशील रूप से टाइप किया हुआ, बहुउद्देशीय प्रोग्रामिंग भाषा है। यह एक साफ और एक समान वाक्यविन्यास सीखने, समझने और उपयोग करने के लिए त्वरित होने के लिए डिज़ाइन किया गया है। कृपया ध्यान दें कि अजगर 2 आधिकारिक तौर पर 01-01-2020 के समर्थन से बाहर है। फिर भी, संस्करण-विशिष्ट पायथन सवालों के लिए, [अजगर -२.०] या [अजगर -३.x] टैग जोड़ें। पायथन वेरिएंट (जैसे, ज्योथन, PyPy) या लाइब्रेरी (उदा।, पांडस और न्यूमपी) का उपयोग करते समय, कृपया इसे टैग में शामिल करें।