Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   1977

Question About Python discord bot

by Rover1 - 10 March, 2021 - 04:38 PM
This post is by a banned member (Rover1) - Unhide
This post is by a banned member (Rent) - Unhide
This post is by a banned member (Rover1) - Unhide
This post is by a banned member (clap) - Unhide
clap  
Godlike
515
Posts
134
Threads
6 Years of service
#4
To answer your question, it will not work as the embedded invalidation codes are not messages. They are previews (sort of, doesn't really matter what they are right now). All you really have to do is parse the codes and validate them. I'd suggest also redeeming the code as soon as you can validate it, which I'll assume you know how to do.
Code:
 
import requests
import re
import os

from discord.ext import commands
import discord

client = commands.Bot(command_prefix='!')
# commands.Bot(command_prefix='!', self_bot=True) - This is for Selfbots (Using a Discord User's token instead of a application/bot token)

# Creating Discord Bot instance

def validate_code(*args):
    try:
        results = []

        for code in args:
            response = requests.get(f'https://discordapp.com/api/v8/entitlements/gift-codes/{code}')
            body = response.text

            if not any(message in body for message in ['Unknown', 'redeemed already', '404']):
                results.append((True, code))

            elif 'rate limit' in body:
                # Handle it how you will
                pass

            else:
                results.append((False, code))

        return results
    except Exception:
        return False

@client.event
async def on_ready():
    print(f'We have logged in as {client.user}')

@client.event
async def on_message(message):
    matches = re.findall(gift_pattern, message.content)

    if matches:
        gift_codes = list(filter(None, sum(matches, ()))) # Flattening the list of tuples while removing all invalid strings e.g: '', None, etc
        validation = validate_code(*gift_codes)

        # Continue your code

if __name__ == '__main__':
    client.run(os.getenv('TOKEN')) # Normal Discord Bot
    # client.run(os.getenv('TOKEN'), bot=False) - This is for Selfbots (Using a Discord User's token instead of a application/bot token)
 
This is a very basic way of doing it. While working, it is not ideal. I haven't tested it, however, I doubt the speeds will be anything stunning. I'll assume it's around 0.5-8 (depending on your internet connection). That's just one way of doing it, slowly. Not the point though, have a nice day.
Always confirm via PM before dealing with me.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)