#discord-bots

1 messages Β· Page 90 of 1

cloud dawn
rugged epoch
#

if you dont understand something ; come back and ask

rugged epoch
#

google vision ai didnt work

cloud dawn
cloud dawn
rugged epoch
#

and it return DC

#

why does it return DC

dull terrace
#

does discord have any protection against people who bot the bots

rugged epoch
#

which is still easily bypassable

cloud dawn
#

But they do have some tricks up their sleeves.

dull terrace
#

trying to think how you'd implement something that a bot couldn't bypass on discord

rugged epoch
#

get id proof

#

πŸ’€

dull terrace
#

doge_kek im sure that wouldn't kill your bot

wicked atlas
rugged epoch
#

nvm

naive briar
#

You defined it as data

cloud dawn
naive briar
#

Wait

rugged epoch
naive briar
#

They defined it, but you didn't

rugged epoch
#

do u have any files named captcha?

#

including the bot file

#

lol i didnt even read this

#

show the code

naive briar
#

Only thing that I can see is the error's description

rugged epoch
#

first off : dont use nextcord

#

second off : dont kick the user if they fail once

#

some captchas are so hard to read i literally cant solve them

#

how many times have u failed a captcha

#

give them 3 attempts

#

make a dict

#

ok

#

make a json file

#
def writeJson(userID: str, attempts):
    with open('questions.json', 'r+') as file:
        fileData = json.load(file)
        fileData["captchaAttempts"][userID] = attempts
        file.seek(0)
        json.dump(fileData, file, indent=4)```
#

check their attempts by loading the json, similar to this but just dont dump anything

#

then if they get it wrong, subtract their attempts by 1 and writeJson again

#

after u subtract the json and it reaches under 0

#

kick them

rugged epoch
unkempt canyonBOT
#
Missing required argument

pep_number

#
Command Help

!pep <pep_number>
Can also use: get_pep, p

Fetches information about a PEP and sends it to the channel.

#

Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

grand willow
rugged epoch
naive briar
#

It can't open the font file

grand willow
#

But I randomly saw it here

rugged epoch
#

i spent ages trying to find that example

#

no

glad cradle
#

consider using aiofiles instead of open

rugged epoch
#

its ur pc error πŸ˜‚

glad cradle
#

!pypi aiofiles

unkempt canyonBOT
rugged epoch
#

C drive is really strict on files opened from unknown source

shrewd apex
#

use aiofiles to open then use json.loads to load it

rugged epoch
#

thats why i use usb

shrewd apex
#

that way it won't block

glad cradle
rugged epoch
#

use aiofiles

shrewd apex
#

but u can still easily corrupt the file

rugged epoch
#

or bytesIO

#

bytesio will do the file without actually making it

#

like cache

cloud dawn
#

"bytesio will do the file" 😏

shrewd apex
shrewd apex
rugged epoch
#

does the captcha module directly make the file

#

or does it return bytes content

#

lemme see ur code

rugged epoch
glad cradle
shrewd apex
rugged epoch
#

oh

shrewd apex
#

u need to run it in a thread

rugged epoch
#

discord thread or python thread

shrewd apex
#

discord ofc

glad cradle
#

your bot will be ratelimited

rugged epoch
#

u will get ratelimited a lot

#

is this bot public

#

or for personal use

#

it may be alright if u limit the number of threads

#

and then close them for inactivity

glad cradle
rugged epoch
#

work on the economy asap

#

and make it hard

#

but not too hard where people get bored

#

and not repetitive

#

if you add tons of new stuff to the economy then more and more people will come

toxic sentinel
#

ded

cloud dawn
#

Why would you need intent for modlogging?

naive ermine
#

Hello

#

I have an error says event loop closed and it come out of no where it doesnt let me run my code

dull terrace
#

more features != better bot

wicked atlas
dull terrace
#

focus on making one very good feature

naive ermine
#

Anyone can help me?

slate swan
#

nice

cloud dawn
naive ermine
#

I want some help

slate swan
#

multiple features make bots messy tbh

#

take carl for example

cloud dawn
slate swan
naive ermine
glad cradle
dull terrace
#

imagine if google decided to make their homepage cluttered with stuff like weather and other random features

slate swan
naive ermine
dull terrace
slate swan
slate swan
dull terrace
#

im switching to templeOS tbh

cloud dawn
wicked atlas
cloud dawn
slate swan
# naive ermine

you haven't enabled intents on your bot's developer page but are seeking disabled intents from your code

dull terrace
cloud dawn
# naive ermine

I also recommend fully reading the traceback since it also literally contains the url.

naive ermine
#

oh ok

cloud dawn
#

Why would you want to know that?

naive ermine
slate swan
#

you can't find who deleted a message

cloud dawn
#

Well actually the audit log could have a pretty good guess on who removed it.

slate swan
#

rarely captures it

wicked atlas
slate swan
#

edited not delete

naive briar
#

message.guild returned None

wicked atlas
#

Was the message sent in a server, or a dm?

dull terrace
#

i think that happens if someone tries to use it in a dm

rugged epoch
#

only if ur bot can handle it

#

one way i can think of doing this is have a dict with unix timestamp

#

and then every 1 hour you loop through every user to see when their last command was and if its smaller than the unix timestamp u saved then send a dm to them

#

prob a bad idea but its one way

vale wing
#

Yes

dull terrace
#

autor

slate swan
#

otter

vale wing
#

Yeah you need to have a table with users and last command usage times, store the time when on_command (or on_command_invoke idr) and in the loop just select all users with time less than 3 days ago from current time, send them a message and delete them from table to prevent bot from continuosly sending messages

dull terrace
#

...

edgy tundra
#

How to import discord _games
Because I'm getting error

ModuleNotFoundError : No module named 'discord_games'

vocal snow
#

What is discord_games

light violet
#

How do i register both appcomamnds and prefixed commands

slate swan
#

my on_message event don't let that the commands work

edgy tundra
#

When i typing
pip install discord-games
Another error coming is
File "stdin>", line 1 pip install discord-games ^ SyntaxError : invalid syntax

#

@vocal snow

light violet
#

@app_commands.command(name="set")
async def set(interaction:discord.Interaction):
await interaction.response.send_modal(name())
await interaction.response.send_message("Done")

#

Not getting the slash helpppp

vocal snow
light violet
#

@vocal snowcan u help me

vocal snow
light violet
#

@vocal snow cant use modal with taht

#

I need interaction

vocal snow
#

Then how will you use prefixed command

light violet
#

I just want to have this set cmd as slash

#

And rest prefixed

vocal snow
#

Then what's the issue

#

Just use different decorators

light violet
#

How to do that

#

I need to add the app commands

#

Gimme a test example without classes with both prefixed cmd1 and slash cmd2

vocal snow
#

See second pinned message for slash command guide

spring needle
#

Why it says botBase.load_extension was never awaited

vocal snow
spring needle
light violet
#

@vocal snow btw how do i add all the guilds

vocal snow
light violet
#

@vocal snow self.tree.copy_global_to(guild=discord.Object(id=12345678900987654))

vocal snow
#

Just omit that line

#

Sync the commands globally

light violet
#

@vocal snow

class SlashBot(commands.Bot):
    def __init__(self) -> None:
        super().__init__(command_prefix=">", intents=discord.Intents.default())
        
    async def setup_hook(self) -> None:
        #self.tree.copy_global_to(guild=discord.Object(id=12345678900987654))
        await self.tree.sync()

#bot = SlashBot()

client = SlashBot() ```
#

Got no response to my prefixed cmd as well as slash cmd btw hybrid cmds are working with only slash

vocal snow
#

Send full code

#

!paste

unkempt canyonBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

vocal snow
#

What is format_emb

grand willow
silk fulcrum
dull terrace
#

what are some must have channels for a bot server

silk fulcrum
#

that it would be a dict

grand willow
vocal snow
#

You need to add it to the bot

light violet
#

How

vocal snow
#

Or just use @bot.tree.command decorator

light violet
#

I did client.tree.sync in on_ready

#

Which i didnot include here

vocal snow
#

What is it

#

...what

#

It's a string, send the string

silk fulcrum
#

if format_emb is a class which i think it is, this might me shadowing it

#

idk if that affects anything tho

vocal snow
#

No it's supposed to be a string

light violet
#
@client.tree.command(name="set")
async def set(interaction:discord.Interaction):
  await interaction.response.send_modal(name())
  await interaction.response.send_message("Done") ```@vocal snow  still cmd not registered
silk fulcrum
#

oh sorry, .format is a string method

#

i forgot bruh :dumb:

#

wait now u have a f string and using format on it wt

vocal snow
#

But you aren't providing ctx to .format

silk fulcrum
#

and shouldn't it be 0.author.id

#

in .format things

vocal snow
#

Not necessary

silk fulcrum
#

oh ok

vocal snow
#

You can pass as positionals or as kwargs

light violet
#

@vocal snow hey why is my cmd not added to bot

vocal snow
#

Anyways, idk why an fstring isn't being used

vocal snow
light violet
#

@client.tree.command(name="set")
async def set(interaction:discord.Interaction):
await interaction.response.send_modal(name())
await interaction.response.send_message("Done")

#

@client.event
async def on_ready():
await client.add_cog(anti(client))
#tree = app_commands.CommandTree(client)
await client.tree.sync()

#

This was above the previous one

silk fulcrum
#

cogs in on_ready 🀒

light violet
#

It was importted

#

It worked btw

silk fulcrum
#

that way to load cogs is so ass btw

light violet
#

Ok nvm

#

Why is my slash not registered

patent wagon
#

replit is being dumb

#

it used to work yasterday fine

#

and today i get hit with this error:

#
File "main.py", line 63, in <module>
    client.run(os.environ['TOKEN'])
  File "/home/runner/Yoink-Bot/venv/lib/python3.8/site-packages/discord/client.py", line 828, in run
    asyncio.run(runner())```
fading marlin
#

firstly, you shouldn't be hosting on replit. Secondly, is that the whole error?

patent wagon
#
File "main.py", line 63, in <module>
    client.run(os.environ['TOKEN'])
  File "/home/runner/Yoink-Bot/venv/lib/python3.8/site-packages/discord/client.py", line 828, in run
    asyncio.run(runner())
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/runner/Yoink-Bot/venv/lib/python3.8/site-packages/discord/client.py", line 817, in runner
    await self.start(token, reconnect=reconnect)
  File "/home/runner/Yoink-Bot/venv/lib/python3.8/site-packages/discord/client.py", line 745, in start
    await self.login(token)
  File "/home/runner/Yoink-Bot/venv/lib/python3.8/site-packages/discord/client.py", line 580, in login
    data = await self.http.static_login(token)
  File "/home/runner/Yoink-Bot/venv/lib/python3.8/site-packages/discord/http.py", line 801, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/home/runner/Yoink-Bot/venv/lib/python3.8/site-packages/discord/http.py", line 680, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 429 Too Many Requests (error code: 0): ```
patent wagon
#

that is FREE

fading marlin
patent wagon
shrewd apex
patent wagon
#

cos its the same code as yasterday

shrewd apex
#

only way rn cycle heroku and railway accs

patent wagon
shrewd apex
#

if u have a cc just use aws

patent wagon
#

cc?

shrewd apex
#

credit card

patent wagon
#

o

#

i kinda want it to be free

#

y not to use replit?

shrewd apex
#

just go check discord bot hosting

light violet
#

How to get interaction.user namr

#

Name*

shrewd apex
#

.name

light violet
#

Lemme try that

#

Thanks it workee

#

Worked

pulsar solstice
#

what is this error in json

#
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'are'```
#

'are'?

quaint epoch
#

You're attempting to check for a key that doesn't exist

cloud dawn
pulsar solstice
#
@bot.command(aliases=["8ball", "8balls", "eb"])
async def eball(ctx, question):
    random_reply = random.choice(r8ball)
    with open("eballdata.json", 'r') as f:
        questions = json.load(f)
    if str(question) in questions:
        await ctx.send(questions[str(question)][random_reply])
    else:
        await ctx.send(random_reply)
        questions[str(question)][random_reply]
        with open("eballdata.json", 'w') as f:
            json.dump(questions, f)```
pulsar solstice
limber bison
#

can i trigger a command with a button or other command ?

cloud dawn
#

Looks good to me

pulsar solstice
#

bruh seriously ignoring me?

#

I got forgoted so quick

hybrid pond
#
https://discord.com/oauth2/authorize?response_type=code&client_id=995673825511485470&scope=identify+guilds.join&state=15773059ghq9183habn&redirect_uri=136.243.69.245/discordauth

anyone got i idea why it isnt working?

slate swan
#

in the dev page?

#

on the page of your app

#

go to your current application > bot page

#

scroll down a bit and enable message intents

#

but really I'm just trolling

#

don't listen to me

#

why are you using str.format though and that too is wrong, why dont you use f-strings?

#

stop reposting

#

what do i need to install for the modules that arent installed its confusing me

unkempt canyonBOT
#

7. Keep discussions relevant to the channel topic. Each channel's description tells you the topic.

slate swan
#

emb_format.format

slate swan
#

ty

#

no, just remove that and put an f before the emb_format string, which makes it an f-string (see !f-string in #bot-commands for more info), and then you can directly reference that variable in the value like value=emb_format

#

!e```py
name = "Ashley"
string = f"My name is {name}"
print(string)

unkempt canyonBOT
#

@slate swan :white_check_mark: Your 3.11 eval job has completed with return code 0.

My name is Ashley
slate swan
#

smh no

winners = 0
emb_format = f"winners {winners}"
embed.add_field(..., value=emb_format)
wicked atlas
pulsar solstice
#

how can I make my 8ball responces parmanent

slate swan
hybrid pond
slate swan
pulsar solstice
pulsar solstice
#

sorry of double

slate swan
#

make a cache maybe?

#

a dictionary that stores the last question and the response provided, then use a library like difflib or fuzzywuzzy to check the string similarity and send back the same response or a new one

pulsar solstice
#

where can I learn this

slate swan
#

is basic python knowledge impl

pulsar solstice
#

okay

slate swan
#

oh god, emb_format was just an example, remove that winners and all
just simple havre the format_emb and then pass it to the value. no parameters at all

format_emb = ...
embed.add_field(..., value=format_emb)
await send(embed=embed)

easy as that

#

right

#

define members and winner_count too lmao

#

before you use them in format_emb

#

members = ... winner_count = ...

kind wind
#

Is there like an only_for_server_ids function?

slate swan
#

huh? wdym?

#
members = ...
winner_count = ...
format_emb = ...
slate swan
#

huh

kind wind
#

like i have 3 servers and i want a command to restrict to 1 server

feral frost
#

Question:
How do i put 2 buttons in 1 button callback ?

Code:

async def button(ctx):
    buttons = [
        Button(label="Title", style=discord.ButtonStyle.primary),
        Button(label="Title", style=discord.ButtonStyle.primary)
        ]
    
    
    async def button_callback(interaction: discord.Interaction):
        first_embed = discord.Embed(title="Title", description="Description")
        await interaction.response.edit_message(content="Editing embed!")

    buttons.callback = button_callback   

    view = View(timeout=None)
    view.add_item(buttons)
    await ctx.send(content=None, view=view)```

**Error:**
```discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'list' object has no attribute 'callback'```
slate swan
unkempt canyonBOT
#

@discord.ext.commands.guild_only()```
A [`check()`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that indicates this command must only be used in a guild context only. Basically, no private messages are allowed when using the command.

This check raises a special exception, [`NoPrivateMessage`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.NoPrivateMessage "discord.ext.commands.NoPrivateMessage") that is inherited from [`CheckFailure`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").

If used on hybrid commands, this will be equivalent to the [`discord.app_commands.guild_only()`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.guild_only "discord.app_commands.guild_only") decorator. In an unsupported context, such as a subcommand, this will still fallback to applying the check.
slate swan
slate swan
feral frost
#

ok

feral frost
feral frost
slate swan
#

just the same ig?

feral frost
#

?

slate swan
feral frost
#
async def button(ctx):
    buttons = [
        Button(label="Title", style=discord.ButtonStyle.primary),
        Button(label="Desc", style=discord.ButtonStyle.primary)
        ]
    
    
    async def button_callback(interaction: discord.Interaction):
        first_embed = discord.Embed(title="Title", description="Description")
        await interaction.response.edit_message(content="Editing embed!")    

    buttons[0].callback = button_callback
    buttons[1].callback = button_callback   

    view = View(timeout=None)
    view.add_item(buttons)
    await ctx.send(content=None, view=view)```
feral frost
slate swan
#

yes this will work except you'll get an error at the view.add_item.line

feral frost
#

lets see

#

yep

slate swan
#
for button in buttons: view.add_item(button)
``` replace it with this and it should work
feral frost
#

and i keep the list on top ?

slate swan
#

yea

digital charm
#
@bot.command(aliases=['bal'])
async def balance(ctx, user:discord.Member = None):
  if user is None:
    user = ctx.author
    cash, crystals, event_pearls, weapon_shards, fusion_earring, merging_stones, enhancing_stones = await get_bal(user)
    
    
    balem = discord.Embed(title=f"**{user}'s balance**", color=discord.Color.purple())
    nl = '\n'
    balem.description = f"**Cash:** {cash} {nl} **Crystals:** {crystals} {nl} **Event Pearls:** {event_pearls} {nl} **Weapon Shards:** {weapon_shards} {nl} **Fusion Earrings:** {fusion_earring} {nl} **Merging Stones:** {merging_stones} {nl} **Enhancing Stones:** {enhancing_stones}"
    balem.set_footer(text='Alaias - bal')
    await ctx.send(embed=balem)
``` I can look my bal but cannot look at other's bal, why is that?
feral frost
slate swan
feral frost
# slate swan yea

it does thanku very much πŸ˜„ but 1 more question how do i now add another value to the buttons ? ```

slate swan
#

can you elaborate wdym by "add another value"

feral frost
slate swan
#

well then create 2 different callbacks and assign the callback accordingly

feral frost
#

can i not do smth like button.values or smth

slate swan
#

there's a much better way to do this if you know how classes work

slate swan
#

miss ashley will explain you the rest i gtg

slate swan
# feral frost i dont

well then it would look like this ```py
async def callback1( ...): ...
async def callback2(...): ...

buttons[0].callback = callback1
buttons[1].callback = callback2

feral frost
#

ok

#

can i not use this

#

if buttons.values[0] == "Title": ?

slate swan
#

callback1 and callback2 being functions like your button_callback function earlier

feral frost
#

or ssmth

shut axle
#

How do I do the background for created_at?

feral frost
#

like the select interaction

slate swan
#

thats another thing, totally not related

slate swan
feral frost
slate swan
#

an

#

!d discord.utils.format_dt

unkempt canyonBOT
#

discord.utils.format_dt(dt, /, style=None)```
A helper function to format a [`datetime.datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)") for presentation within Discord.

This allows for a locale-independent way of presenting data using Discord specific Markdown...
slate swan
feral frost
#

why does it work for select but not for button ?

slate swan
#

because a button is a button and a select is a select

feral frost
feral frost
feral frost
#

AttributeError: 'list' object has no attribute 'values'

#

the same list error again

shut axle
#

discord.utils.format_dt()
what do I need to type if I want to get the years? (Created At)

sick birch
shut axle
#

So how I get the years?

sick birch
#

!d datetime.datetime perhaps the attributes of the class may be of interest

unkempt canyonBOT
#

class datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)```
The *year*, *month* and *day* arguments are required. *tzinfo* may be `None`, or an instance of a [`tzinfo`](https://docs.python.org/3/library/datetime.html#datetime.tzinfo "datetime.tzinfo") subclass. The remaining arguments must be integers in the following ranges...
shut axle
#

To get this one

cloud dawn
#

What's wrong with ctx.guild?

sick birch
digital charm
# slate swan the indentation, rest of the code after `user = ctx.author` has to be un-indente...

smth like this?


@bot.command(aliases=['bal'])
async def balance(ctx, user: discord.Member=None):
    if user is None:
        user = ctx.author
        cash, crystals, event_pearls, weapon_shards, fusion_earring, merging_stones, enhancing_stones = await get_bal(user)
        nl ='\n'
        balem = discord.Embed(title=f"**{user}'s balance**", color=discord.Color.purple())
        balem.description = f"**Cash:** {cash} {nl} **Crystals:** {crystals} {nl} **Event Pearls:** {event_pearls} {nl} **Weapon Shards:** {weapon_shards} {nl} **Fusion Earrings:** {fusion_earring} {nl} **Merging Stones:** {merging_stones} {nl} **Enhancing Stones:** {enhancing_stones}"
        balem.set_footer(text='Alaias - bal')
        await ctx.send(embed=balem)
cloud dawn
shut axle
cloud dawn
# shut axle Yes yes how?
Use <t:TIMESTAMP:FLAG> to send it

Available flags:

t: Short time (e.g 9:41 PM)
T: Long Time (e.g. 9:41:30 PM)
d: Short Date (e.g. 30/06/2021)
D: Long Date (e.g. 30 June 2021)
f (default): Short Date/Time (e.g. 30 June 2021 9:41 PM)
F: Long Date/Time (e.g. Wednesday, June, 30, 2021 9:41 PM)
R: Relative Time (e.g. 2 months ago, in an hour)
shut axle
kind wind
#

why this error-

cloud dawn
shut axle
#

discord.utils.format_dt()
and what should be inside the brackets to show me the years..

cloud dawn
#

!d discord.utils.format_dt

unkempt canyonBOT
#

discord.utils.format_dt(dt, /, style=None)```
A helper function to format a [`datetime.datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)") for presentation within Discord.

This allows for a locale-independent way of presenting data using Discord specific Markdown...
cloud dawn
#

dt meaning datetime object

#

Styles most likely a string with the format flag.

feral frost
#

i think you can do smth like {ctx.author.mention} or smth instead of <@...>

#

also

#

put an f infront of it

#

infront of " "

#

np

mossy jacinth
#

Hello everyone! I want to add a command thats only usable in a ticket channel. The ticket channel always has a new number at the end. So how could i do this?

mossy jacinth
#

no a add command so you can add someone from the server to the ticket

grand willow
# mossy jacinth no a add command so you can add someone from the server to the ticket
@client.command()
async def add_user(ctx, channel : discord.TextChannel = None, user : discord.Member = None):
    if channel == None:
        await ctx.send("Enter a User to add")
    else:
        channel = channel or ctx.channel
        overwrite = channel.overwrites_for(user)
        overwrite.send_messages = True
        overwrite.read_messages = True
        await channel.set_permissions(user, overwrite=overwrite)
        await ctx.send(f'Added {user.mention} to the Channel')
#

gives them perms to see and talk in the channel

mossy jacinth
#

but isnt that command available in every channel then?

grand willow
mossy jacinth
#

but how? I only want it to be used in tickets and the names are like ticket-#1 and i dont want someone use it in other channels that are only for staff

grand willow
grand willow
#

no idea what that means

left idol
#

if i ping the user before sending the embed will it cache the user?

rare echo
soft heart
#

Is it possible to get the message id of a message when a button attached to the message gets pressed?

sage otter
teal tide
#

hey how can i make a double use command for instance if i run it once it will say hi but if i run it again it will say goodbye? i also want to make a channel private via my discord bot

slate swan
#

i need help making a dropdown menu

#

i have a button option and after someone clicks the button i need the bot to send a dropdown menu option

bold kernel
#

Hi everyone, is it possible to use selenium with discord api ?

sick birch
quaint epoch
#

selenium was meant to interact with browsers

bold kernel
#

selenium is sync ?

bold kernel
sick birch
#

Yes, that's what I'm saying

bold kernel
#

is there any way other ?

#

Like for requests, instead of requests : there is aiohttp for async

#

the same thing for selenium

#

or the same to scrape data of dynamic website

slate swan
#

idk how to make it so it sends an embed after a button is pressed can someone help?

#
if data[str(guild.id)]['users'][str(int.user.id)]['open_tickets'] <= data[str(guild.id)]['max_tickets']:```
#

it continues to create a ticket even though there is more tickets than aloud

#

max ticekts is 2 and i can create well over that

#

int is the interaction

slate swan
#

everything is synced

#

so i do len(data) <= len(data)?

#

idk how to make it so it sends an embed after a button is pressed can someone help?

slate swan
#

did you do a callback for t he button?

#

so when someone presses button a

#

i need it to send an embed

#

so then it does await ctx.channel.send(embed = embed)

#

did you do a clalback for it?

#

im new to python idek what that means ;-;

#

a callback function is something that adds onto the button after it is pressed

#

is yours a class or just a simple inside the command

#

import discord
client = discord.Client(intents=discord.Intents.default())
class YourBetterClassName(discord.ui.View):
def init(self):
super().init()
self.value = None

@discord.ui.button(label='Hi', style=discord.ButtonStyle.green)
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
    await interaction.response.send_message('hi', ephemeral=True)
    self.value = True
    self.stop()

@discord.ui.button(label='Help or Question', style=discord.ButtonStyle.grey)
async def b(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message('Please Ping a Mod/Owner', ephemeral=True)
self.value = False
self.stop()

@client.event
async def on_guild_channel_create(channel):
await channel.send(view=YourBetterClassName())

#

this is my code

#

should i do

#

instead of send message do send embed after interaction

slate swan
# slate swan import discord client = discord.Client(intents=discord.Intents.default()) class ...
import discord
client = discord.Client(intents=discord.Intents.default())
class YourBetterClassName(discord.ui.View):
    def init(self):
        super().init()
        self.value = None

    @discord.ui.button(label='Hi', style=discord.ButtonStyle.green)
    async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message('hi', ephemeral=True)
        self.value = True
        self.stop()

@discord.ui.button(label='Help or Question', style=discord.ButtonStyle.grey)
async def b(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message('Please Ping a Mod/Owner', ephemeral=True)
        self.value = False
        self.stop()

@client.event
async def on_guild_channel_create(channel):
    await channel.send(view=YourBetterClassName())```
#

ok so you have a class

#

yes

#

on the await interaction.response.send_message(embed = embed, ephemeral = True)

#

should i just remove that

#

https://cog-creators.github.io/discord-embed-sandbox/

#

because i dont want it to send a message i want it to send a embed

#

here is a gerat embed creator but doesnt have some features

#

only on the first button

#

yeah thats what i used

slate swan
#

its embed = embed

#

so

#

@discord.ui.button(label='Hi', style=discord.ButtonStyle.green)
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message(embed = embed, ephemeral = True)

#

then put the embed code

slate swan
#

then it should send your embed everytime your button is pressed

#

ok it works

#

but now its not showing the 2nd button option

#

hmmm

rocky trench
#

Indent error

#

Are you new to python?

#

Indents are hard to explain how they work but once u know how they work, it's easy

rare echo
#

!indents

unkempt canyonBOT
#

Indentation

Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.

Example

def foo():
    bar = 'baz'  # indented one level
    if bar == 'baz':
        print('ham')  # indented two levels
    return bar  # indented one level

The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.

Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines

More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation

slate swan
rocky trench
# slate swan yes

I'd say read the text above and if u don't get it google about indents

slate swan
#

i tried all different indentations

rocky trench
slate swan
#

@discord.ui.button(label='Hi', style=discord.ButtonStyle.green)
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
embed=discord.Embed(title="Hi", description="Hiii.", color=0xc32828)
embed.add_field(name="123 πŸ“Ž", value="2", inline=False)
embed.add_field(name="456 πŸ“Ž", value="1", inline=False)
await interaction.response.send_message(embed = embed, ephemeral = True)

#

this is my code

rocky trench
#

!code

unkempt canyonBOT
#

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

rocky trench
#

If u send ur code without using this way we can't see indents

slate swan
#
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
    embed=discord.Embed(title="Hi", description="Hiii.", color=0xc32828)
embed.add_field(name="123 πŸ“Ž", value="2", inline=False)
embed.add_field(name="456 πŸ“Ž", value="1", inline=False)
      await interaction.response.send_message(embed = embed, ephemeral = True)```
rocky trench
#

Enter after the py

#

At the start

slate swan
#
@discord.ui.button(label='Hi', style=discord.ButtonStyle.green)
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
    embed=discord.Embed(title="Hi", description="Hiii.", color=0xc32828)
embed.add_field(name="123 πŸ“Ž", value="2", inline=False)
embed.add_field(name="456 πŸ“Ž", value="1", inline=False)
      await interaction.response.send_message(embed = embed, ephemeral = True)```
rocky trench
#

Also, could u maybe screen it? I'm on phone

slate swan
#

screen share?

rare echo
#

nah screenshot

slate swan
#

oh ok

sick birch
#

yet it's indented like it is

#

so python is confused on what you mean

slate swan
#

yeah i tried different indentations

#

all didnt work ;-;

sick birch
#

it's not about trying different indentations, it's not a game. You need to know how to define functions and which lines of code are part of it

#

That beings said, how do you define lines of code to be within a function?

rare echo
slate swan
#

i got it to work

#

but this happend

#

this is so frustrating

#
@discord.ui.button(label='Hi', style=discord.ButtonStyle.green)
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
    embed=discord.Embed(title="Hi", description="Hiii.", color=0xc32828)
    embed.add_field(name="123 :paperclip:", value="2", inline=False)
    embed.add_field(name="456 :paperclip:", value="1", inline=False)
    await interaction.response.send_message(embed = embed, ephemeral = True)
    self.stop()```
#

@slate swan this is right?

sick birch
slate swan
#

what are you trying to create

#

this?

#

are you leavingg code out?

#
import discord
client = discord.Client(intents=discord.Intents.default())
class YourBetterClassName(discord.ui.View):
    def init(self):
        super().init()
        self.value = None

@discord.ui.button(label='Hi', style=discord.ButtonStyle.grey)
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
    embed=discord.Embed(title="Hi", description="Hiii.", color=0xc32828)
    embed.add_field(name="123 :paperclip:", value="2", inline=False)
    embed.add_field(name="456 :paperclip:", value="1", inline=False)
    await interaction.response.send_message(embed = embed, ephemeral = True)
    self.stop()

@discord.ui.button(label='Help or Question', style=discord.ButtonStyle.grey)
async def b(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message('Please Ping a Mod/Owner', ephemeral=True)
        self.value = False
        self.stop()

@client.event
async def on_guild_channel_create(channel):
    await channel.send(view=YourBetterClassName())```
#

this is my whole code

slate swan
#

when someone makes ticket

#

why not when you create the ticket it auto matically sends the embed?

#

because it needs button options

wicked atlas
# slate swan

A view only includes message components. You need to send some form of content, whether it be message content or an embed.

slate swan
#

i just need it to send a embed after button "hi" is pressed

wicked atlas
#

Like I said, you need to include some kind of message content. For example,

await channel.send("these are some buttons:", view=YourBetterClassName())
slate swan
#

ok

wicked atlas
#

I would also take the suggestion of YourBetterClassName and use a better class name

slate swan
#

so send that before embed

wicked atlas
#

before what embed?

rocky trench
#

Well

#

U cant just send a naked button. It has to be stickied to a message

#

See the buttons below?

slate swan
#

yes

rocky trench
#

They're stickied to the message

slate swan
#

ok

rocky trench
#

U need to send a message and add buttons to that message

slate swan
#

so u want me to put something

#

like await interaction.response.send_message('Please Ping a Mod/Owner', ephemeral=True)

#

before the embed

rocky trench
#

u can add buttons on an embed too

#

U just need some kind of message to add the buttons to

slate swan
#

didnt support that

rocky trench
#

It does

slate swan
#

still doesnt work

#

2022-09-21 22:51:06 ERROR discord.client Ignoring exception in on_guild_channel_create

#
@discord.ui.button(label='Hi', style=discord.ButtonStyle.grey)
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
    await interaction.response.send_message('Please Ping a Mod/Owner', ephemeral=True)
    embed=discord.Embed(title="Hi", description="Hiii.", color=0xc32828)
    embed.add_field(name="123 :paperclip:", value="2", inline=False)
    embed.add_field(name="456 :paperclip:", value="1", inline=False)
    await interaction.response.send_message(embed = embed, ephemeral = True)
    self.stop()```
#

ugh

rocky trench
#

What error

#

U didn't tell it to add the buttons either

slate swan
#

still empty message

slate swan
rocky trench
#

Adding buttons to a message require the view parameter

#

await ctx.channel.send_message("Hello", view = Yourview())

slate swan
#

undefined name ctx

slate swan
rocky trench
#

Its an example

#

Are you using slash commands

slate swan
#

no

#

its guild on channel create

rocky trench
#

Send code

#

I see a lot of mistakes in ur code above

#

Please look up the docs and their examples

slate swan
# rocky trench Send code
import discord
client = discord.Client(intents=discord.Intents.default())
class YourBetterClassName(discord.ui.View):
    def init(self):
        super().init()
        self.value = None

@discord.ui.button(label='Hi', style=discord.ButtonStyle.grey)
async def a(self, interaction: discord.Interaction, button: discord.ui.Button):
    await interaction.response.send_message('Hi', ephemeral=True)
    embed=discord.Embed(title="Hi", description="Hiii.", color=0xc32828)
    embed.add_field(name="123 :paperclip:", value="2", inline=False)
    embed.add_field(name="456 :paperclip:", value="1", inline=False)
    await interaction.response.send_message(embed = embed, ephemeral = True)
    self.value = True
    self.stop()
  

@discord.ui.button(label='Help or Question', style=discord.ButtonStyle.grey)
async def b(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message('Please Ping a Mod/Owner', ephemeral=True)
        self.value = False
        self.stop()

@client.event
async def on_guild_channel_create(channel):
    await channel.send(view=YourBetterClassName())```
rocky trench
#

Its the wrong decorator

#

Check the GitHub examples please

slate swan
#

!examples

#

!decorators

unkempt canyonBOT
#

Decorators

A decorator is a function that modifies another function.

Consider the following example of a timer decorator:

>>> import time
>>> def timer(f):
...     def inner(*args, **kwargs):
...         start = time.time()
...         result = f(*args, **kwargs)
...         print('Time elapsed:', time.time() - start)
...         return result
...     return inner
...
>>> @timer
... def slow(delay=1):
...     time.sleep(delay)
...     return 'Finished!'
...
>>> print(slow())
Time elapsed: 1.0011568069458008
Finished!
>>> print(slow(3))
Time elapsed: 3.000307321548462
Finished!

More information:
β€’ Corey Schafer's video on decorators
β€’ Real python article

patent wagon
#

im watching a vid on how to make a discord bot and i came across this line

#

should that data be reviled?

slate swan
patent wagon
#

its this vid:

#

Learn how to code a Discord bot using Python and host it for free in the cloud using Repl.it.
🚨Note: At 16:43, Replit now has a new method for environment variables. Check the docs: https://docs.replit.com/programming-ide/storing-sensitive-information-environment-variables

Along the way, you will learn to use Repl.it's built-in database and cr...

β–Ά Play video
#

1:01:17

sick birch
#

the discord bot videos are garbage

#

they're probably using replit or heroku for hosting

patent wagon
#

but can somone do someting with that info

patent wagon
slate swan
#

got it to work

#

:DDD

#

how do i make it so its not only i can see it and other people can see it

novel kelp
slate swan
#

yeah i realised

#

dyk how to make it so when the bot sends that its not only you can see this?

#

ostias

zealous jay
#

send your error

#

and your code, please

slate swan
#

async for user in channel.guild.audit_logs(limit=1):
await ban(user, reason=None, delete_message_days=1)

zealous jay
#

oh

slate swan
#

self is not defined

#

xd

zealous jay
#

are you in a cog?

#

ok you are probably not in a cog

slate swan
#

I'm at an event xd

zealous jay
#

uhmm, how is your class named

#

Bot?

slate swan
zealous jay
#

yes, for your bot?

#

do await bot.ban

slate swan
#

okok

#

AttributeError: 'Bot' object has no attribute 'ban'

sick birch
unkempt canyonBOT
#

await ban(*, delete_message_days=..., delete_message_seconds=..., reason=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Bans this member. Equivalent to [`Guild.ban()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild.ban "discord.Guild.ban").
sick birch
#

why would you be able to call ban on the bot instance

zealous jay
#

im

#

stupid

slate swan
sick birch
#

I'm guessing bot.ban() was an older version? Like bot.say() or similar?

zealous jay
#

I should probably go to sleep, I didn't even realized

zealous jay
slate swan
#

aaaaaa what

zealous jay
#

I cant help you rn I need some sleep and cant help anyone like this...

sick birch
#

.ban needs to be called on a member instance

zealous jay
#

user.ban

#

instead of bot.ban

#

i think its better to use member instead of user

#

because a member refers to an user inside a guild

#

right?

slate swan
zealous jay
#

I didn't mean that

#

There you are giving "user" the value of an audit log entry

slate swan
#

@sick birchSorry for the mention, how can I solve this problem?

unkempt canyonBOT
#
Nope.

No documentation found for the requested symbol.

sick birch
#

nvm

#

!d discord.Guild.ban

unkempt canyonBOT
#

await ban(user, *, reason=None, delete_message_days=..., delete_message_seconds=...)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Bans a user from the guild.

The user must meet the [`abc.Snowflake`](https://discordpy.readthedocs.io/en/latest/api.html#discord.abc.Snowflake "discord.abc.Snowflake") abc.

You must have [`ban_members`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Permissions.ban_members "discord.Permissions.ban_members") to do this.
slate swan
sick birch
#

What do you not understand?

slate swan
#

Sorry if I say something wrong, I speak Spanish

compact swift
#

!d discord.on_message

sick birch
#

even though you passed in limit=1 it's an async iterator

#

it really only has one element but it's still an iterator

slate swan
sick birch
#

I'm not sure you can flatten it

#

!d discord.Guild.audit_logs

unkempt canyonBOT
#

async for ... in audit_logs(*, limit=100, before=..., after=..., oldest_first=..., user=..., action=...)```
Returns an [asynchronous iterator](https://docs.python.org/3/glossary.html#term-asynchronous-iterator "(in Python v3.10)") that enables receiving the guild’s audit logs.

You must have [`view_audit_log`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Permissions.view_audit_log "discord.Permissions.view_audit_log") to do this.

Examples

Getting the first 100 entries:

```py
async for entry in guild.audit_logs(limit=100):
    print(f'{entry.user} did {entry.action} to {entry.target}')
```...
sick birch
#

refer to the documentation here

slate swan
#

Can i add nitro emojis to my embed like moneytoburn ?

slate swan
slate swan
#

m?

#

\πŸ˜Άβ€πŸŒ«οΈ

#

@slate swan

#

\

slate swan
#

if len(data[str(guild.id)]['users'][str(int.user.id)]['open_tickets']) >= len(data[str(guild.id)]['max_tickets']):```
#

\πŸ’€

slate swan
#

doesnt work even when i set my tickets to 0 could i get help?

#

why isnt it sending emoji id

slate swan
slate swan
#

add a nitro emoji to my embed

#

like moneytoburn

#

where are you putting the emoji

#

because some places will not work and will just show :emoji:

#

in the text

#

no i did \ emoji

#

yes theat send the emoji name and id

#

<ablobhammer:586031065219596302>

#

<πŸ˜‰ :emojiid>

#

does work??

#

idk how to get emoji id

#

just do back slash your emoji

#

:w:

#

it sends that

#

nvm

#

?

#

it worked

#

977412187473719296 is the id

#

does anyone know how to make it so everyone can read this?

#

instead only you can see this

#

remove ephemeral

slate swan
#

ok

#

if len(data[str(guild.id)]['users'][str(int.user.id)]['open_tickets']) >= len(data[str(guild.id)]['max_tickets']):```
it wont go past this
#

any reason why??

#

does anyone have an idea on how I can make this?

torn sail
slate swan
#

ik how to make the embed

torn sail
#

what parts do u not know

slate swan
#

tags, page system, minute ago

torn sail
#

well im not sure about tags and page system but i can help you the the minute ago

#

<t:unixtimestamphere:R>

#

!d discord.utils.format_dt if you have a datetime.datetime object

unkempt canyonBOT
#

discord.utils.format_dt(dt, /, style=None)```
A helper function to format a [`datetime.datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.10)") for presentation within Discord.

This allows for a locale-independent way of presenting data using Discord specific Markdown...
zealous jay
#

@slate swan did you fix your problem?

slate swan
#

I'm looking for someone to help me code a Restore bot, so if my server gets deleted i can restore my members

sick birch
slate swan
#

How Letoa or restorecode did it

sick birch
slate swan
#

can someone help? its saying this is invalid syntax

fading marlin
#
  1. Reset your token
  2. why are you creating 2 instances of the same thing and naming them completely different things?
slate swan
#

huh?

slate swan
#

i dont understand number 2

slate swan
#

do if message.content.lower

#

So if they do !BlAckJack

#

It will work

#

the

#

bot = commands.Bot ('!')

#

has syntax error

#

thats my problem

fading marlin
#

just stay with one

slate swan
#

so make it

#

client = commands.client('!')

fading marlin
#

no, remove the whole bot = commands.Bot(...) thing, just use client as your bot object

#

also, just as best practice, you should name it bot instead of client

slate swan
#

how would i have a prefix then?

fading marlin
#

you're already setting a prefix in your bot constructor

slate swan
#

all i need to figure out

#

is to make this not a syntax error

fading marlin
#

you're not closing your parenthesis

slate swan
#

they're closed?

#

nvm

#

now theres an error on this

#

undefined name "prefix"

fading marlin
#

that's basic python, you're not defining prefix, and I'm guessing you're not defining intents either

slate swan
#

ok

#

i got this

#

now its saying this

fading marlin
#

read the error lol

slate swan
#

u dont see where i put intents?

#

i put intents under bot = commands

#

im VERY new to python

fading marlin
#

you need to put the intents inside the bot constructor

slate swan
#

hmm

#

i need to figure out how to do that

sick birch
unkempt canyonBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

severe rampart
#

commands.Bot takes multiple required arguments

slate swan
#

should i add client = commands.Bot(command_prefix = prefix, intents = intents

slate swan
#

and remove the inents = discord.intents.all()

#

hmm

#

now its saying invalid syntax

sick birch
# slate swan

I think learning Python first is really a necessity here

slate swan
#

Its only a 2 minute fix

#

just need a little help

sick birch
#

Because you'll keep running into issues like this, that are all 2 minute issues. That adds up

#

It's only going to discourage you, since you're fighting with the language instead of using it as a tool

slate swan
#

I just need help on where to end the parenthesis man.

sick birch
#

The problem here is that

  1. You're missing a closing parenthesis
  2. You still have 2 instances of the same thing (commands.Bot)
  3. You're defining intents after referencing it
sick birch
#

I really don't like turning people away from coding what they enjoy, but at certain points they'll end up doing that to themselves by not knowing intermediate python before discord.py, which is not a beginner's library

slate swan
#

im stupid asf i forgot how to use fore for like 15 mins

#

😭

sick birch
slate swan
#

ok

#

i imported colorama instead of doing

#

from colorama import fore

robust fulcrum
#

Guys how i can get image from message in dpy?

sick birch
unkempt canyonBOT
slate swan
#

Anybody got any resolution ? This is the error im recieving await message.reply('What do you need to acquire from the One and Only Suspect. @glass ledge', mention_author=True) ^ IndentationError: unindent does not match any outer indentation level

nimble acorn
slate swan
#

Thank you !

nimble acorn
#

np

robust fulcrum
rugged shadow
#

you didn't enable the message_content intent

robust fulcrum
rugged shadow
#

even in the dev portal?

robust fulcrum
toxic sentinel
#

h

#

hhihuhukhuh

#

xsdf

#

rfrfrsf

#

f

slate swan
#

how to make a cooldown command for a app_command?

#
import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="!", self_bot=False)
@bot.event
async def on_ready():
    print("f Loaded.")

@bot.command()
async def hi(ctx):
    embed = discord.Embed(title="r", color=discord.Color.from_rgb(0, 64, 255))
    embed.add_field(name="hi", value="hi", inline=False)
    await ctx.send(embed=embed)

bot.run("my token",bot=True)

my discord bot doesnt even seem to be working its like 1200 lines, no errors not even this does anything only the bot goes online i cant do any commands though

#

and yes i have my token in the real code

keen talon
#

Damn when was 2.0 released for dpy

sick birch
sick birch
austere vale
#

is it possible to have a discord bot block a user so they cant send them dms?

slate swan
sick birch
keen talon
slate swan
sick birch
slate swan
#

yeah ik

keen talon
#

When will the other versions be out

slate swan
#
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix="!", intents=intents, self_bot=False)
@bot.event
async def on_ready():
    print("f Loaded.")

@bot.command()
async def hi(ctx):
    embed = discord.Embed(title="Elusive - API", color=discord.Color.from_rgb(0, 64, 255))
    embed.add_field(name="hi", value="hi", inline=False)
    embed.set_image(url="https://cdn.discordapp.com/attachments/971538759516581888/971585692016709663/ezgif.com-gif-maker_1.gif")
    await ctx.send(embed=embed)

bot.run("MTAy",bot=True)
austere vale
#

is it possible to have a discord bot block a user so they cant send them dms?

naive briar
slate swan
#

Traceback (most recent call last): File "C:\Users\User\Desktop\api\a.py", line 4, in <module> intents.message_content = True

#
import discord
from discord.ext import commands
intents = discord.Intents.default()

bot = commands.Bot(command_prefix="!", intents=intents, self_bot=False)
@bot.event
async def on_ready():
    print("f Loaded.")

@bot.command()
async def hi():
    embed = discord.Embed(title="Elusive - API", color=discord.Color.from_rgb(0, 64, 255))
    embed.add_field(name="hi", value="hi", inline=False)
    embed.set_image(url="https://cdn.discordapp.com/attachments/971538759516581888/971585692016709663/ezgif.com-gif-maker_1.gif")
    await ctx.send(embed=embed)``` removed the message content thing but still bot only goes online doesnt respond
vocal snow
#

self_bot kwarg doesn't exist and you need to enable message content intents

slate swan
#

How do I make this thumbnail go up?

#

This embed looks so ugly.

vocal snow
#

Can you put Snake Game on the next line

slate swan
#

I'm not sure how but I'll try

#

Oh, \n

rocky trench
#

channel wasnt found

#

u did an overwrite on channel

#

wait, lemme take a look first

#

I might havent looked good enough

#

can you print channel for me

slate swan
#

why even in the name of god is get_channel inside a try/except block

vocal snow
#

They want to make debugging their program harder ig

rocky trench
#

there u got the issue

slate swan
#

pass in the correct channel id...

tidal hawk
#

@slate swan do you even try solving problems yourself? Most of these functions is basically done by this community xD

vale wing
#

Bbb

#

Make AI chatbot with tensorflow because why not

robust fulcrum
#

Guys do we need to select application.commands scope to make slash commands work?

#

Pls anyone tell fast

rugged shadow
#

yes

slate swan
#

first make the "soon" stuff. that's gonna take your time lol

robust fulcrum
#

Guys how can I get member avater image instead of url ?
I want to paste the user avater on image using pil

unkempt canyonBOT
#

await read()```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Retrieves the content of this asset as a [`bytes`](https://docs.python.org/3/library/stdtypes.html#bytes "(in Python v3.10)") object.
robust fulcrum
#
    @commands.Cog.listener("on_member_join")
    async def join(self,member):
        img = Image.open("welcome.jpeg")
        avatar = Image.open(member.avatar)
        img.paste(avatar)
        img.save("avatar2.jpeg")

Guys why i getting this error

naive briar
robust fulcrum
naive briar
robust fulcrum
naive briar
#

And if you want to open the image from bytes with PIL, you have to pass it as io.BytesIO or any bytes-like object

import io

...

avatar_data = await member.avatar.read()
avatar = Image.open(io.BytesIO(avatar_data))
slate swan
#

do you think that I can made a simple bot in one day

shrewd apex
#

yes

#

u can make one in 5 mins

digital charm
digital charm
digital charm
#

how do I add this(I am unable to remember the term)
if there are a few questions, let call them tasks and there are 30 of them for each(planet, read the full thing, then u might be able to understand what I mean)
and there are the normal 8 planets so how do I make it so that the tasks(basically a few questions related to the planet and on answering the correct answer u get a specific amount of money) of a planet do not mix up with other planet and the person can select by doing the following cmd - (server prefix) planet (name of the planet/smth similar(provided by the bot) to select a particular)
Example(server prefix - ! ):
! planet
(the bot sends an embed stating:
1 - Mercury, 2 - Venus, 3 - Earth, 4 - Mars, 5 - Jupiter, 6 - Saturn, 7 - Uranus, and 8 - Neptune)
and on doing:
! planet 4
the bot sends the following embed:
You are now one planet Mars(4)
and finally on doing:
! task
the bot sends and embed(example):
Which is the biggest moon for planet Mars:
1️⃣ - Phobos
2️⃣ - Titan
3️⃣ - Deimos
the bot reacts with 1️⃣ , 2️⃣ , 3️⃣
and if the user with the correct a specific amount gets added to their wallet...

PS - Sorry for making it so lengthy...

dull terrace
#

super vague question, you might as well just be asking how to make a bot

soft heart
digital charm
dull terrace
digital charm
dull terrace
dull terrace
#

then you use the custom ids that you pass in the buttons to see which they press

digital charm
#

then do I do an if statement to check and send the tasks/questions according or something else?

slate swan
#

!d discord.Guild.leave

unkempt canyonBOT
#

await leave()```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Leaves the guild.

Note

You cannot leave the guild that you own, you must delete it instead via [`delete()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild.delete "discord.Guild.delete").
patent wagon
#
    raise HTTPException(response, data)
discord.errors.HTTPException: 429 Too Many Requests (error code: 0): <!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<title>Access denied | discord.com used Cloudflare to restrict access</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/main.css" />```
#

error on replit

#

discord bot with webscraper

brazen raft
#

It looks like you have been rate limited

patent wagon
#

wtf does that even mean

brazen raft
#

So this instance of replit is banned from it

slate swan
#

ratelimited cuz replit

patent wagon
brazen raft
patent wagon
#

how do i do that

brazen raft
#

What library are you using

#

Those listed on the Discord Developer Portal should not be rate limited

patent wagon
#

import discord
from discord.ext import commands

brazen raft
#

That tells me nothing about the library you are using

patent wagon
vestal dagger
brazen raft
#

If you are on replit, you should be able to see what libraries you have installed

brazen raft
#

It's in the packages tab in the editor

#

Well, the editor is a different view

#

It's one of the icons on the left side of the window, also where the settings for replit are

patent wagon
#

that helps?

brazen raft
#

Why do you have four different dependencies sections

brazen raft
#

You don't need discord, just discord.py

#

Try uninstalling it

patent wagon
#

ok

#

gimi a sec

brazen raft
#

Also I see you are using requests which isn't asynchronous and therefore is unfit for this kind of a project

#

discord.py comes with aiohttp which is asynchronous

patent wagon
cerulean folio
#

Hi guys !
I have a serious concern since I just hit the end of the progression curve regarding basic python and discord.py and I now came back to my first bot project that I made (still working and used by 10k+ people thanks to all of u guys that helped me).

I'm getting into some advanced and professional practice such as cleaning my code and make it so it's pep8 friendly. Also reshaping the code to add OOP to it (so it's quite a big redesign).

All of these are going well but where my struggle is with learning unit testing...
And here's my question:

# Returns True if user_id exists, False otherwise
async def check_id(bot, user_id):
    try:
        await bot.fetch_user(user_id)
        return True
    except discord.NotFound:
        return False

# sayhi command will say hi to the requested id. Syntax: sayhi <discord_user_id>
@bot.command(name='sayhi')
async def sayhi(ctx):
        target = ctx.message.content.split(' ')[1]
        if await check_id(bot, target):
            ctx.send(f'{ctx.author}, you just requested me to say hi to {target} !')
        else:
            ctx.send(f'{ctx.author}, you requested a wrong ID.')

So since here I'm using discord.py library, with its classes, how am I supposed to unit test these using the unittest library?

limber bison
#

should i create different db for each server named with server id and in db make tables ?
or any other approch ?

brazen raft
# patent wagon but it works fine with it?

Whenever an HTTP/S request is made using requests, the bot's code waits for the request to finish and is effectively dead for all Discord is concerned (so the connection may be closed/lost)

slate swan
limber bison
#

it will be effactive ?

slate swan
patent wagon
#

what was the name of it?

slate swan
brazen raft
limber bison
cerulean folio
slate swan
brazen raft
#

@patent wagon, your replit instance might have been rate limited without your fault because of other people with whom you share the replit instance which have been rate limited (or a combination of both since you are all accessing discord.com in parallel)

cold trout
#

is there any way of storing discord channel msg history with bot? like in txt file or any other format

slate swan
#

use a db

patent wagon
patent wagon
cerulean folio
patent wagon
#

says this but it also said i uninstalled discord

brazen raft
#

Well whatever

#

By the way are you accessing discord.com using requests or aiohttp explicitly

#

That matters too

slate swan
patent wagon
#

ill swich to aiohttp

brazen raft
#

If you are explicitly accessing discord.com, it might just be that you accessed it too much

slate swan
#

stop using replit to avoid that error

patent wagon
brazen raft
patent wagon
slate swan
brazen raft
patent wagon
#

im seding a command in discord and it acess another page

slate swan
#

you're using a website thats known for causing that issue, not using it is the only solution

patent wagon
brazen raft
patent wagon
brazen raft
#

Well then it's unrelated

brazen raft
patent wagon
#

fuck

patent wagon
#

any other free ways to host it for free?

cerulean folio
#

thank you again sarth, you're a hero in this channel dude

tidal hawk
#

Yep

brazen raft
tidal hawk
#

Not sure how things work in pycord - but perhaps they have example about it in their repository

patent wagon
brazen raft
#

Just run it on your machine

#

If you have spare hardware on which you can run it, better do it

patent wagon
brazen raft
#

Preferably so

patent wagon
#

bru

tidal hawk
#

get raspberry pi

patent wagon
#

what about heroku

brazen raft
#

If you trust AWS, you can use their free tier

tidal hawk
#

heroku doesn't offer free tier - after this month

patent wagon
#

bruuuuuuuuuuh

tidal hawk
#

Just invest 3-5$ per month into some vps and y can run multiple bots

patent wagon
#

not a fan of paying

tidal hawk
#

I use Vultr and it's running 10 bots

patent wagon
#

id have to sell a bot

#

and i want my code to be free

brazen raft
#

Have the customer pay for the hosting

tidal hawk
#

xD

patent wagon
#

ight

tidal hawk
#

That's actually really smart - my hosting fee is 10$ but I ask each client 15$ xD

patent wagon
#

ok

#

i might do that

brazen raft
#

That's taking 5$ every hosting plan

#

What an easy sure money