Skip to content

Instantly share code, notes, and snippets.

View crazygmr101's full-sized avatar
🏫
In school and work, so I might be slow to respond

Daniel Nash crazygmr101

🏫
In school and work, so I might be slow to respond
View GitHub Profile
import asyncio
import json
import random
from typing import Callable, Tuple
import discord
from discord.ext import commands
import lib.checks
import datetime
import discord
from discord.ext import commands
import re
import asyncio
import lib.checks
from discord.ext.commands import BucketType, Cooldown, CooldownMapping
import datetime
import discord
from discord.ext import commands
class EntranceGate(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.ROLE = 694105778339971112
import main
app = main.app
# asking for a yes/no user confirmation for deleting something
# NOTE: if the user cancels, this function returns None, *NOT* the user's response
await ctx.send("Type yes to delete the file and no to cancel")
confirmation = _input(ctx, str, cancel_str="no", ch=lambda x: x.lower() in ("yes", "no"),
err="Input yes or no", del_err=60, del_response=True)
# this will return None or "yes"
if not confirmation:
# the user canceled, so _input returned None
# do stuff here
@crazygmr101
crazygmr101 / input.py
Last active June 7, 2020 19:22
a `input` like function for discord.py bots
# ctx - required - a commands.Context of the commands
# typ - required - the type you want to return
# cancel_str - the string that a user will type to cancel
# ch - a function/lambda that is checked for validity
# err - error string
# del_error - the time to wait before deleting the error message
# del_response - delete the user's response
# return_author - return (result, author) otherwise just return result
# check_author - whether to wait for an author matching ctx.author
import asyncio
import json
import socket
from typing import Dict
import discord
from discord.ext import commands, tasks
from libs.mcrcon import MinecraftClient
async def _input(self, ctx, typ: type, cancel_str: str = "cancel", ch: Callable = None, err=None, check_author=True,
return_author=False, del_error=60, del_response=False):
def check(m):
return ((m.author == ctx.author and m.channel == ctx.channel) or not check_author) and not m.author.bot
while True:
try:
inp: discord.Message = await self.bot.wait_for('message', check=check, timeout=60.0)
if del_response:
await inp.delete()