#discord-bots

1 messages · Page 1017 of 1

slate swan
#

which iirc the meta class calls the init and call and new dunders

#

meta class

#

yes metaclasses

#

I'm bad at python names

paper sluice
#

a class which subclasses from type

slate swan
#

its just a class which changes the behavior of a class

atomic wolf
#

Okay, sort of like "this."

#

?

paper sluice
slate swan
#

Wo

atomic wolf
#

ah, that's in this code snippit too

paper sluice
#

__init__ is the constructor if ur familiar with that

atomic wolf
#

def __init__(self):

slate swan
#

the init is basically just like the parameters of the class

slate swan
#

which self means the class itself

#

i would recommend you check out Corey Schafer which he has some good oop tutorials

#

Ok

atomic wolf
#

init is the class structure and self is the user?

slate swan
#

OOP in Python is yikes CS_HappyChick

atomic wolf
#

no, that didn't make sense nvm

slate swan
paper sluice
#

@atomic wolf what other lanng are u familiar with other than python?

atomic wolf
#

I know a little bit of java and C#.

slate swan
atomic wolf
#

But it's honestly been a while.

slate swan
#

C is cool

atomic wolf
#

I took C# and Introduction to Computer Logic (which was java oriented)

slate swan
slate swan
atomic wolf
#

Dropped out for the derptieth time.

slate swan
#

C++

#

C Plus Plus

#

oh lol

slate swan
#

file.cpp

#

Python\Python39\lib\site-packages\disnake\ext\commands\interaction_bot_base.py:733: SyncWarning: Failed to overwrite commands in <Guild id=967099836585377885> due to 403 Forbidden (error code: 50001): Missing Access
warnings.warn(

#

eh

paper sluice
#

when u type ipp instead of i++

slate swan
#

Make sure you invite with the scope

atomic wolf
#

oauthtoken

#

is that a specific user or somting?

slate swan
#

https://discord.com/oauth2/authorize?client_id=ID&scope=bot+applications.commands&permissions=x

#

x

#

x=8

#

Never invite a bot with administrator permissions

#

I'm surprised Discord even allows this

#

very dangerous

#

And useless

#

Put the right permissions and only those you need

#

..

#

Your bot has a ban and mute command?
Everyone: permissions=8

#

Lmao

#

Totally me

#

Discours should remove the administrator permission from bots honestly

#

But idh mute cmd 🥺

paper sluice
#

huh? no

slate swan
#

All permissions your bot needs can be put manually and you never need administrator on a bot

#

As simple as that

slate swan
#

...

#

But then Discord are the first to complain because bots are being used in a malicious way

paper sluice
#

Ash Ketchum

slate swan
#

Yet they don't remove it

#

huh?

#

Krypton doesn't care he just continue his typing

#

krypton just hates discord allot🙀

#

Yeah because people apparently still believes bots actually need administrator permission

huh? no

#

Wait wait wait old dev badhe no way

#

yeah

#

🥺

#

krypton is old

#

i remember him when i was a noob and he used to help me lol

#

Still

#

was 8 or so months ago

vocal plover
slate swan
#

Like anti nuke bot

#

vco😳

#

There always are exceptions, you just face them once in a lifetime

vocal plover
#

there should at least be something that says "Are you absolutely sure you want to give this bot admin? It can be a dangerous permission to grant."

lyric apex
#

Discord Ui Button Supports In 1.7.3?

slate swan
#

Why not make it, just like some intents, something you need to have to prove you actually need it.

quaint epoch
slate swan
#

Luckily I don't have any server so no problem

#

No nukes

vocal plover
slate swan
#

Which would then prevent people from putting it with 8

#

..

torn sail
vocal plover
#

I've always hated that Rythm, a music bot, asked for admin

#

like, no

slate swan
vocal plover
#

you do not need that, ever, you're a music bot

slate swan
vocal plover
#

The most likely place for it to be seen would be the discord-api-docs repo, but believe me it's been suggested many a time and Discord have other priorities

paper sluice
slate swan
#

Imagine getting ignored

#

Yeah, will probably do that - thanks!

atomic wolf
#

class CustomClient(discord.Client): def __init__(self): super(CustomClient, self).__init__() with open("allykeys.json") as jfile: data = json.load(jfile) self.oauthsecret = data["oauthsecret"] self.oauthtoken = data["oauthtoken"] self.consumerkey = data["consumerkey"] self.api = AllyAPI(self.oauthsecret, self.oauthtoken, self.consumerkey, response_format="json")

#

is this like getting data from jfile for authorization?

#

to call AllyAPI?

paper sluice
#

what is AllyAPI? where did u get this code?

slate swan
#
embed.add_field(name="Prefix", value=len, inline=False)
``` correct?
atomic wolf
#

Any ideas hat the allykeys.json file is?

slate swan
#
from disnake import CommandInteraction
from disnake.ext.commands import Bot

bot = Bot()

@bot.slash_command(
    name="hello",
    description="A simple hello command.",
    guild_ids=[ID],
)
async def hello(inter: CommandInteraction) -> None:
    await inter.response.send_message("Hello!")

@bot.slash_command(
    name="ping",
    description="A simple ping command.",
    guild_ids=[ID],
)
async def ping(inter: CommandInteraction) -> None:
    await inter.send(f"Pong! {bot.latency * 1000:.2f}ms")

@bot.listener()
async def on_message(message: Message) -> None:
    if "badword" in message.content:
        await message.delete()

bot.run("token lol")
#

Ok so i tried this and i get an error

paper sluice
#
{
    "consumerkey": "YOUR CONSUMER KEY",
    "oauthsecret": "YOUR OAUTH SECRET",
    "oauthtoken": "YOUR OAUTH TOKEN"
}

@atomic wolf its on their website

slate swan
#

@bot.listener()
AttributeError: 'Bot' object has no attribute 'listener'

paper sluice
#

probably bot.event

vocal plover
#

it's just @bot.listen()

paper sluice
#

👀

slate swan
#

ik i asked before but anyone know how to use bot.wait_for in an extension (not cog)

slate swan
torn sail
#

No

blissful oar
#

hey

#

i am having problems with my discord bot

#

can someone help

slate swan
quaint epoch
paper sluice
blissful oar
#
import discord
from My_token import token
import requests
import json

token_ = token()
client = discord.Client()


def get_quote():
    response = requests.get("https://zenquotes.io/api/random")
    json_data = json.loads(response.text)
    quote = json_data[0]['q'] + " -" + json_data[0]["a"]

    return (quote)


@client.event
async def on_ready():
    print("We have logged in as {0.user}".format(client))


@client.event
async def on_message(message):
    if message.author == client.user:
        return
    quote = get_quote()
    if message.content.startswith("$inspire"):
        quote = get_quote()
        await message.channel.send(quote)


client.run(token_)
slate swan
# quaint epoch in the typehint
@bot.listen()
disnake.Message def on_message(message: Message) -> None:
    if "badword" in message.content:
        await message.delete()```
quaint epoch
slate swan
#

so like this?

blissful oar
blissful oar
slate swan
#

i'm just dumb don't mind me xd

quaint epoch
#
@bot.listen()
async def on_message(message: disnake.Message):
    if "badword" in message.content:
        await message.delete()```
blissful oar
quaint epoch
#

use commands.Bot, not Client, and use commands, not on_message

slate swan
blissful oar
slate swan
#

huh

paper sluice
quaint epoch
#

!resources --- would be a nice place to start

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.

slate swan
slate swan
quaint epoch
#

since discord bots fall on moderate to complex

slate swan
quaint epoch
#

learning python extensively before making a bot helps a lot

slate swan
#

anyone?

quaint epoch
#

for example -

torn sail
#

It would be the same as normal

paper sluice
slate swan
#

but not self.bot.wait_for cuz im not using cogs

quaint epoch
#
try:
  await bot.wait_for(event='name', timeout=60, check=func)
except asyncio.exceptions.TimeoutError:
  print('the wait timed out!')
else:
  print('the wait was finished!')```
quaint epoch
#

they do the same thing

paper sluice
quaint epoch
#

!rule 6

unkempt canyonBOT
#

6. Do not post unapproved advertising.

slate swan
quaint epoch
#

!d discord.ext.commands.Bot.wait_for

unkempt canyonBOT
#

wait_for(event, /, *, check=None, timeout=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Waits for a WebSocket event to be dispatched.

This could be used to wait for a user to reply to a message,
or to react to a message, or to edit a message in a self-contained
way...
slate swan
quaint epoch
torn sail
quaint epoch
#

mmmmm

slate swan
#

Jose

quaint epoch
#

houston we have a problem

jovial dock
#

can i make one command only work in a specific channel?

quaint epoch
slate swan
#

Ye

quaint epoch
#

!d discord.ext.commands.check

unkempt canyonBOT
#

@discord.ext.commands.check(predicate)```
A decorator that adds a check to the [`Command`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command") or its
subclasses. These checks could be accessed via [`Command.checks`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command.checks "discord.ext.commands.Command.checks").

These checks should be predicates that take in a single parameter taking
a [`Context`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Context "discord.ext.commands.Context"). If the check returns a `False`-like value then
during invocation a [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure") exception is raised and sent to
the [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") event...
slate swan
# paper sluice its `commands.Bot` not bot
  reaction, user = await commands.bot.wait_for("reaction_add", timeout=60, check=check2)
AttributeError: module 'discord.ext.commands.bot' has no attribute 'wait_for'

The above exception was the direct cause of the following exception:```
jovial dock
#

thx

slate swan
#

Rly

quaint epoch
#

it's commands.Bot, not .bot

slate swan
#

ohhhhhh

#

im dumb

#

Ok

torn sail
#

You need an instance of bot

slate swan
#

^

quaint epoch
slate swan
#

🪃

torn sail
#

If your in a command you can use ctx.bot

slate swan
#
Client.wait_for() missing 1 required positional argument: 'event'```
#

noow this error

#

Bro

torn sail
#

You need to wait for something

paper sluice
paper sluice
#

do u know what an argument is?

slate swan
paper sluice
#

do u know how to add arguments to a function?

slate swan
#

ye

paper sluice
#

then just do that

slate swan
#

but whats the event argement?

paper sluice
#

its the name of the argument

slate swan
slate swan
paper sluice
#

¯_(ツ)_/¯

#

what do u want to put in it?

#

@bot.event nice

slate swan
slate swan
#

wait who needs help here?

torn sail
#

Ur argument is ctx

slate swan
#

me

#

Me

torn sail
#

Should be message

slate swan
#

I need a life and a brain

slate swan
torn sail
#

No ur using message in the function tho

#

But the arg is ctx

paper sluice
feral halo
#

having arguement to be ctx isn't wrong

slate swan
torn sail
#

You will get message is undefined

slate swan
#

hello there

#

use @commands.cooldown(1, time, commands.BucketType.user)
sets timer for per user to use this command

#

Hello there

paper sluice
feral halo
#
@bot.event
async def func(ctx, a):
  await ctx.send(a)
slate swan
#

Ok

slate swan
#

Huh?

torn sail
#

Oh edited it👍 add the time to a dictionary and check the difference

feral halo
#

just do

await ctx.send```
paper sluice
slate swan
slate swan
torn sail
feral halo
# slate swan ()

it's no need to correct me with ()
because they should put them in themself

slate swan
#

...

#

Msg. Send?

paper sluice
feral halo
#

ohhhhhh i got it now
it's an on_message event
and ctx returns message
sooo

slate swan
# slate swan ()

nah need to show small details dpy is an intermediate they should know about parenthesis

slate swan
#

message.channel.send()

paper sluice
#

what ever, u get the point

slate swan
#

Make a bot instance

slate swan
torn sail
#

ctx.bot if in a command

paper sluice
feral halo
#
await bot.wait_for('reaction_add', timeout=60, check=check2)
slate swan
feral halo
slate swan
slate swan
paper sluice
sage otter
#

I mean you don’t have to help.

slate swan
feral halo
slate swan
slate swan
paper sluice
feral halo
#

who are you

paper sluice
#

lol

slate swan
#

basically discord bots are mixture of asynchronous programming,OOP and just good knowledge about python

slate swan
feral halo
#

i don't recognize having freddy as friend

#

oh it's you

slate swan
#

i got same about me with that minesweeper

feral halo
#

yeah i remember the minesweeper

sage otter
paper sluice
#

alright, im now actually going to fix this seg fault, been pissing me off since 3 days

slate swan
quaint epoch
#

it should be easy

paper sluice
feral halo
sage otter
#

Hello Okimii loli_wave

slate swan
#

hi hipithink

paper sluice
#

cpp is just annoying, esp seg faults, they dont tell u whats wrong and just dont work

feral halo
#

compare to rust..

wanton veldt
quaint epoch
#

rust gives you, frighteningly descriptive errors

feral halo
#

it got the best ERROR

quaint epoch
#

i know from experience

slate swan
#

to me the only scary things of cpp is how powerful and vulnerable it can be by just writting a bit of lines of code

quaint epoch
#

that's why it's slower

feral halo
#

!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.

slate swan
quaint epoch
#

i'd pick rust over cpp any day

quaint epoch
paper sluice
#

in cpp ur actually coding in a piece of RAM.. random stuff pops up if u r not carefull

slate swan
#

yeah

wanton veldt
#

ty

quaint epoch
paper sluice
#

that too

cloud dawn
#

No it isn't.

cursive spindle
#

why i cant start my bot?

feral halo
#

maybe you DIDN'T set a welcome channel

cursive spindle
#
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 563, in connect
    self.ws = await asyncio.wait_for(coro, timeout=60.0)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py", line 494, in wait_for
    return fut.result()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\gateway.py", line 306, in from_client
    socket = await client.http.ws_connect(gateway)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 132, in ws_connect
    return await self.__session.ws_connect(url, **kwargs)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client.py", line 769, in _ws_connect
    raise WSServerHandshakeError(
aiohttp.client_exceptions.WSServerHandshakeError: 503, message='Invalid response status', url=URL('wss://gateway.discord.gg/?encoding=json&v=6&compress=zlib-stream')
feral halo
cloud dawn
#

You're asking about reading a json on a hosting platform.

wanton veldt
#

if you understand

feral halo
#

this?

channel_id = guilds_dict[str(member.guild.id)]
wanton veldt
#

y

feral halo
#

got it

sage otter
slate swan
#

isnt the error quite descriptive?

cloud dawn
slate swan
#

it failed the handshaked and returned a 503

slate swan
#

😳

cloud dawn
slate swan
#

i need knowledge lemon_sentimental

short silo
cloud dawn
slate swan
sage otter
#

how is this guy gonna ask for help and take like 2 years to respond

slate swan
#

😭

cloud dawn
#

If he/she needs further help we'll know.

cloud dawn
#

There was a recent incident that occurred here regarding the same topic.

slate swan
cloud dawn
#

Mostly if a handshake fails is because someone is trying to manipulate the api.

#

Think such of having a mobile status for bots.

slate swan
#

manipulate as not following its orders and trying to bypass stuff?

cloud dawn
#

Yes.

slate swan
#

bad stuff😳

slate swan
#

how else can u make an economy/data storing bot

#

wouldnt matter

#

json isnt for storing data.

sick birch
slate swan
#

and his question is about checking a file with heroku which still would fall into the thread of discord bot hosting which it still doesnt

slate swan
#

hey

#

is there any reason for on_member_leave not working ?

#

it just doesnt get triggered

#

why is that

#

ping me if you have any answer ^^

sick birch
slate swan
#

which intent do I need

#
intents.reactions = True
intents.members = True
intents.guilds = True```
#

I have these

sick birch
#

I see

#

Did you try a print statement on_member_leave to see if it gets called?

slate swan
#

I tried

#

but nothin

sick birch
#

And someone is actually leaving the server?

slate swan
#

yeah

sick birch
#

Ah I think I know what's up

slate swan
#

what is it

sick birch
#

As I suspected

slate swan
#

wha

sick birch
#

!d discord.on_member_remove

unkempt canyonBOT
#

discord.on_member_join(member)``````py

discord.on_member_remove(member)```
Called when a [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") join or leaves a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild").

This requires [`Intents.members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.members "discord.Intents.members") to be enabled.
slate swan
#

OOOHHH

#

DAMN

sick birch
slate swan
#

thanks pal lol

sick birch
#

discord.js with typescript actually shows you what events you can listen to. No matter I suppose

slate swan
#

really didnt expect that

#

lol thanks again

sick birch
#

Nope, it's always the small things

sick birch
maiden fable
#

Don't tell me u kidding

sick birch
#

No. Intellisense shows all the events you can listen for using an EventEmitter

maiden fable
#

How do they even accomplish that

sick birch
#

Not that hard really, just a list of string literals

maiden fable
#

Is it like using the typing.Constant typehint?

#

or what was that i forgot

sick birch
#

One way would be

type Events = 
  "MESSAGE_CREATE" |
  "INTERACTION_CREATE" |
  ...
#

Then type the first argument of your EventEmitter to be that

maiden fable
#

Imagine if dpy gets that

sick birch
#
class Client {
  constructor() {
    ...
  }

  on(eventName: Event, callback: ...) {
    ...
  }
}
maiden fable
#

wait wat

sick birch
#

I'm not good with d.js internals but that's one way

maiden fable
#

Ah, so is it like assigning the callback to the event name?

sick birch
#

Sort of

#

Though I'm not sure how the callback parameter type is automatically inferred from the event name

cursive spindle
cursive spindle
slate swan
#

does a guild object have a function bans to get all the ppl banned in the guild?

#

!d discord.Guild.bans

unkempt canyonBOT
#

async for ... in bans(*, limit=1000, before=..., after=...)```
Retrieves an [asynchronous iterator](https://docs.python.org/3/glossary.html#term-asynchronous-iterator "(in Python v3.10)") of the users that are banned from the guild as a [`BanEntry`](https://discordpy.readthedocs.io/en/master/api.html#discord.BanEntry "discord.BanEntry").

You must have the [`ban_members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.ban_members "discord.Permissions.ban_members") permission
to get this information.

Changed in version 2.0: Due to a breaking change in Discord’s API, this now returns a paginated iterator instead of a list...
slate swan
#

You can always use the search function in the documentation

sacred oyster
#

How can I can make a MissingPermissions error

#

?

#

@slate swan

#

Hey

marsh thorn
#

how do i refrence a channel?

#

like for example channel = discord.general

quaint whale
#

Hey Sten, were you able to resolve this problem?

#

Having the exact same error right now..

slate swan
#

It's apperently some sort of bug, it's just to ignore it. 🤷‍♂️

#

Your bot has no permission to add slash commands in the guild

quaint whale
#

Oh weird, thx for your fast reaction 🙂

slate swan
#

Make sure you've invited with the right scope

marsh thorn
#

so does anyone know how to refrence a channel?

slate swan
#

Yes

#

!d discord.ext.commands.Bot.get_channel

unkempt canyonBOT
slate swan
#

!d discord.Guild.get_channel

unkempt canyonBOT
#

get_channel(channel_id, /)```
Returns a channel with the given ID.

Note

This does *not* search for threads...
slate swan
quaint whale
#

Did select those... The slash command I did write got added.

marsh thorn
#

like channel = get_channel(channel_id,id /)?

slate swan
#

This is called object oriented programming.
discord.Guild is your object.
You have such an object with, for example ctx.guild or message.guild.
Then as it says, you need to provide a channel_id, so you'd need to add that as argument when calling the function.

marsh thorn
#

ah alr

#

@slate swan why doesnt this work though channel = discord.get_channel(970359334057951255)?

slate swan
#

Read it again please.

#

I clearly said that:

discord.Guild is your object.
You have such an object with, for example ctx.guild or message.guild.

#

So why do you replace discord.Guild with just discord

slate swan
#
@client.event
async def on_message(message):
    if message.channel.name == 'announcements':
        if message.author.bot:
            return
        if message == '-mention':
            return
        author = message.author
        messageembed=discord.Embed(description=message.content, color=0xffffff)
        await message.delete()
        await asyncio.sleep(0.1)
        await message.channel.send(embed=messageembed)
        print('changed a message to an embed')``` i got this, it works and all but when i do -mention, it still puts it in the embed
marsh thorn
sacred oyster
forest grotto
#
@client.command()
async def say(ctx, msg=None):
 if msg == None:
  await ctx.send(":x: You gotta provide me what you want me to say.")
 else:
  await ctx.send(f"{msg}")
#

say command for anyone

marsh thorn
#

!d discord.Guild.get_channel

unkempt canyonBOT
#

get_channel(channel_id, /)```
Returns a channel with the given ID.

Note

This does *not* search for threads...
marsh thorn
slate swan
#

nothing

marsh thorn
# slate swan nothing

TypeError: Guild.get_channel() missing 1 required positional argument: 'channel_id'

#

it errors this if i leave it as nothing

slate swan
marsh thorn
#

alr ty lemme try

brave forge
#

how to make the team check your role and the role of the mentioned user and if they match , then an error and if they do not match , the command continues execution ?

marsh thorn
velvet tinsel
marsh thorn
velvet tinsel
#

Read the error again

marsh thorn
velvet tinsel
#

It’s missing a required argument???

marsh thorn
#

oh wait

#

do i need to do ('channel_id', 56454515456)

velvet tinsel
#

Bruh

#

Just pass in the ID of a channel

marsh thorn
marsh thorn
velvet tinsel
#

Channel_id argument

velvet tinsel
marsh thorn
velvet tinsel
#

I have a feeling you jumped straight into discord.py without learning the basics of python

slate swan
#

!d discord.Guild.get_channel

unkempt canyonBOT
#

get_channel(channel_id, /)```
Returns a channel with the given ID.

Note

This does *not* search for threads...
velvet tinsel
velvet tinsel
marsh thorn
#

i know some of the basics

velvet tinsel
#

Learn the basics of python first

#

classes functions variables

marsh thorn
#

this is how i learn the basics

#

by creating easy bots

velvet tinsel
#

So that’s why discord bots is so active

slate swan
velvet tinsel
slate swan
#

no they are not.

velvet tinsel
#

They’re part of python OOP

marsh thorn
slate swan
velvet tinsel
#

you’ll need whatever your commands.Bot was

slate swan
slate swan
marsh thorn
strong vessel
#

discord bot invite link with permission set to 0 (no permissions) it will still be able to read and send message, is there any purpose putting the permission in the invite link? Since it adds the additional step on inviting when there is nonzero permission?

marsh thorn
velvet tinsel
slate swan
#

doesnt mean its basic

velvet tinsel
#

Should be basic

slate swan
#

and you still dont know them

#

🙀

velvet tinsel
#

I reviewed them lmao

pliant gulch
velvet tinsel
#

I didn’t care for classes but recently I read more about them

#

did some abstract classes it was fun

slate swan
velvet tinsel
#

Bros typing a whole paragraph 💀

#

Oh he just sent it

slate swan
# vocal plover The most likely place for it to be seen would be the discord-api-docs repo, but ...

Apparently not everyone has the same opinion, I guess they want to keep inviting bots with administrator permissions which they do not need https://i.imgur.com/5Eqwqg9.png - https://github.com/discord/discord-api-docs/discussions/4864

GitHub

Background information Currently every bot can be invited with the ADMINISTRATOR within the permissions field when using an invite link or we can give the bot that permission manually in the server...

pliant gulch
slate swan
pliant gulch
pliant gulch
velvet tinsel
slate swan
#

thats still not my point.

#

my point is its not really basic oop even if python is made out of it yes it would give you better understanding of it but people tend to have trouble with the topic making it a bit more intermediate then basic

velvet tinsel
#

Python is an OOP language surely classes should be required

slate swan
#

How would i get USER ID?

#

from a user

slate swan
marsh thorn
#

channel = discord.Guild.get_channel('channel_id', 970359334057951255)

why doesnt this work?

velvet tinsel
slate swan
#

no from discord bot

velvet tinsel
velvet tinsel
slate swan
#

yeah so if i do for example

/start

it would return their used ID

marsh thorn
velvet tinsel
marsh thorn
#

latter?

velvet tinsel
marsh thorn
#

ah alr

pliant gulch
velvet tinsel
#

If there are options a and b the latter would be b

marsh thorn
# velvet tinsel The last one

umm now it errors i miss one argument:
TypeError: Guild.get_channel() missing 1 required positional argument: 'channel_id'

velvet tinsel
#

a and b and c the latter would be c

rain salmon
#

hello i was wondering how do i make a discord bot ask an input when i do /slayer and then use the resault later?

marsh thorn
velvet tinsel
regal pulsar
#

Uh

velvet tinsel
regal pulsar
#

Which guild are you getting it from lmao

velvet tinsel
#

@slate swan are you there

regal pulsar
slate swan
velvet tinsel
slate swan
#

bro what

velvet tinsel
marsh thorn
slate swan
#

what

velvet tinsel
#

Byeeeee

slate swan
#

i have things to do

velvet tinsel
marsh thorn
regal pulsar
#
guild = bot.fetch_guild(guild_id)
channel = guild.fetch_channels(channel_id)
slate swan
#

its all good

#

!d discord.ext.commands.Bot

unkempt canyonBOT
#

class discord.ext.commands.Bot(command_prefix, *, help_command=<default-help-command>, tree_cls=<class 'discord.app_commands.tree.CommandTree'>, description=None, intents, **options)```
Represents a discord bot.

This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result
anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with
this bot.

This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality
to manage commands...
regal pulsar
#

You may need to await these

velvet tinsel
#

Yeah sarthak the genius

slate swan
#

yes sir

#

slides out

#

🙀

regal pulsar
#

Imagine using discord.Client

velvet tinsel
#

You’re on your own now bye

slate swan
slate swan
slate swan
#

😳

marsh thorn
regal pulsar
#

Why

regal pulsar
slate swan
marsh thorn
regal pulsar
#

bot = commands.Bot()

slate swan
slate swan
# regal pulsar Why

cause get_ uses cache for getting objects
and fetch_ makes an api call, and converts the payload into the object, which get already did!

#

its good practice to make the lowest possible api calls

regal pulsar
#

Yeah

slate swan
#

if you really wanna make sure that you get that object even if its not in the cache, use the or statement py obj = bot.get_x(id) or await bot.fetch_x(id)

velvet tinsel
regal pulsar
#

Hmm

marsh thorn
slate swan
slate swan
slate swan
regal pulsar
#

Turns out fetch makes an api call

wary crystal
slate swan
#

Cogs is something you can pretty much implement by your own!

velvet tinsel
slate swan
#

cogs are easy

#

hm i dont use them ez

slate swan
velvet tinsel
#

I’ve had some trouble locating the files of the cogs but yknow a quick Googling gets them

slate swan
wary crystal
velvet tinsel
#

I’ve always had trouble with file structures idk why it’s like they hate me

regal pulsar
#

It took me an entire week to realise i dont need to use bot.process_commands in my on_message func if im using cogs 💀

slate swan
regal pulsar
#

Lol

slate swan
velvet tinsel
#

It doesn’t even make sense

slate swan
slate swan
velvet tinsel
regal pulsar
#

😨

velvet tinsel
#

The worst duo ever

wary crystal
velvet tinsel
#

Pure pain and suffering and your username would be in high demand

slate swan
#

Ruby and elixir

wary crystal
regal pulsar
#

Instead of changing it all later

slate swan
regal pulsar
#

Just keep it as bot

regal pulsar
regal pulsar
velvet tinsel
regal pulsar
#

Its one of those “why not” situations

slate swan
#

what ever you guys say but i dont see it as dumb or unnecessary its all the samething

regal pulsar
wary crystal
regal pulsar
#

Oh

wary crystal
#

There is a lot of boilerplate under the extension

slate swan
regal pulsar
#

I take back everything i said 💀

slate swan
regal pulsar
slate swan
slate swan
velvet tinsel
regal pulsar
#

My phone’s battery has been on 65 for the last hour

velvet tinsel
slate swan
velvet tinsel
marsh thorn
regal pulsar
slate swan
#

bro

regal pulsar
#

Im on phone

marsh thorn
#

k can anyone show me?

velvet tinsel
regal pulsar
#

Wait what

velvet tinsel
#

IT EXISTS??

slate swan
#

hm, basically a site which redirects u to discord

regal pulsar
#

Wow

#

Lmao

velvet tinsel
regal pulsar
slate swan
velvet tinsel
pliant gulch
#

There's also a modded client called cumcord

velvet tinsel
slate swan
#

😂

#

wtf has happened

velvet tinsel
#

Hello

slate swan
#

sussy clients

regal pulsar
#

BEHOLD

slate swan
#

so much useless dunders and useless imports

regal pulsar
#

🕵️

slate swan
#

that whole code is useless

regal pulsar
#

How dare you

#

That is my masterpiece

slate swan
brave forge
#

how do I make the team look at your role and the role of the mentioned user and if they match , then an error occurs and if they do not match , the team continues execution ?

marsh thorn
#

import os

os.remove('ThisTeribleScript')

velvet tinsel
#

Lol

marsh thorn
#

and they say i dont know the basics

#

🤦‍♂️

#

||jk btw i am terrible||

velvet tinsel
#

We all are

regal pulsar
regal pulsar
#

You can have more than one

brave forge
regal pulsar
#

if role in ctx.author.roles and role in user.roles:
raise RandomError
else:
do this stuff

brave forge
#

@regal pulsarI can't switch to a new one. since everything breaks down for me

slate swan
#

Yes that will work

#

roles attribute has not been changed from 1.7.3 to 2.0 so the same works on both versions

marsh thorn
#

username = str(message.author).split('#')[0]

#

why does it say indent expected?

slate swan
marsh thorn
slate swan
#

!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
#

somewhere up in the source you have an indent error, as the message says

#

your IDE should tell you where it is, if you have linting on.. which you should have

marsh thorn
#

what is an indent error

slate swan
# unkempt canyon

These are indentations, make sure you follow and apply them correctly

slate swan
marsh thorn
#

oh i see now ty

sick birch
#

I don't believe you can. You'll have to make it the same color as your banner/disocrd gray color

#

Have to make it the gray color

rocky hornet
#

is there a premade embed paginator?

tacit canyon
#

Can someone send me the docs for discord.py😅

rocky hornet
tacit canyon
#

Thank you

brave forge
atomic locust
buoyant zodiac
unkempt canyonBOT
#

In order to work with the library and the Discord API in general, we must first create a Discord Bot account.

Creating a Bot account is a pretty straightforward process.

regal pulsar
atomic locust
buoyant zodiac
#

disnake prolly the best out rn

regal pulsar
atomic locust
buoyant zodiac
#

like a clone

regal pulsar
vocal plover
#

My honest personal opinion is that Disnake is currently the best choice, however: disclaimer, I'm a Disnake maintainer/admin, though I do believe that from an objective standpoint based on features and implementation time

slate swan
#

Does anyone have a tip for me where to host my bot? I dont have money and I cant risk to publish the whole code or token or IP adress!

regal pulsar
#
Railway

Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.

regal pulsar
slate swan
regal pulsar
slate swan
fading marlin
# slate swan d

message is discord.Message, not a string. If you'd want to get the content (str) of the message, you'd want to do message.content. However, your applications does have to have the message content intent enabled

slate swan
#

how to do

#

if message in dms = 'dog'

#

then if channel = id:

#

underneath it

regal pulsar
sick birch
#

One glaring issue is that you need an instance of app_commands, not the actual thing itself

#
tree = discord.app_commands.CommandTree()

iirc?

plucky cedar
#

hi how can i get a member object from a user's user id? i can only seem to get a user object. thanks!

sick birch
slate swan
#

Anyone know why my discord bot keeps crashing after 10-20 minutes of idle

full lily
full lily
#

so how is it crashing

slate swan
#

It's not crashing it just aint replying back after 10-20 min

full lily
#

so it's freezing/

slate swan
#

yeah

#

idk why

full lily
#

me neither

#

show some code

slate swan
#

its a API request

#

i'd rather not as i want to keep it private, its a regular discord bot.

full lily
#

i don't know how to help you then

vocal fossil
#

Guys, who can help? I want, to add a command to my bot, which will clear a chat. (!clear (and quality of deleted messages))

slate swan
unkempt canyonBOT
#

await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True, reason=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Purges a list of messages that meet the criteria given by the predicate
`check`. If a `check` is not provided then all messages are deleted
without discrimination...
vocal fossil
supple thorn
sick birch
slate swan
#
import interactions

bot = interactions.Client(token="************************")

@bot.command(
    name="mention",
    description="Mentions everyone",
    scope=966881035252011009,
)
async def mention(ctx: interactions.CommandContext):
    await ctx.send(content = "@everyone")

bot.start()``` im trying to make it @ everyone but it isn't
#

can someone help me asap pls

echo lion
#

might not have permission

#
class ModuleUtils:
    hooks={}
    modules={}
    class Hook:
        def __init__(self,hookf):
            self.hookf=hookf
    class OnMessageHook(Hook):
        pass
    class OnReadyHook(Hook):
        pass
    class OnTypingHook(Hook):
        pass
    def load_optional_modules(*modules):
        output('Loading optional modules\n')
        for module in modules:
            ModuleUtils.modules[module.__name__]=module
            output(f'  Loading {module.__name__}\n')
            if hasattr(module,'service'):
                output(f'    Spawning service\n')
                module.service.start()
                output(f'      Spawned service\n')
                @lambda c:c(module)
                class service_respawner:
                    def __init__(self,module):
                        self.module=module
                        self.respawner.start()
                    @tasks.loop(seconds=5)
                    async def respawner(self):
                        if not self.module.service.is_running():
                            self.module.service.start()
                            print(f'restarted {self.module.__name__} service at {datetime.datetime.today().strftime("%d/%m/%Y, %H:%M:%S")}')
                output(f'      Spawned respawner\n')
            for attr in dir(module):
                if issubclass(type(getattr(module,attr)),ModuleUtils.Hook):
                    output(f'    Hooked method {getattr(module,attr).hookf.__name__} to event {type(getattr(module,attr)).__name__}\n')
                    if type(getattr(module,attr)) in ModuleUtils.hooks:
                        ModuleUtils.hooks[type(getattr(module,attr))].append(getattr(module,attr).hookf)
                    else:
                        ModuleUtils.hooks[type(getattr(module,attr))]=[getattr(module,attr).hookf]
        output('\n')
    handle_hooks=lambda event,*arguments:[hook(*arguments)for hook in ModuleUtils.hooks[event]]if event in ModuleUtils.hooks else[]
#

A useful utility class I made to make discord bots modular

loud junco
#

my bot is working fine
but sometimes it outputs sometime it doesnt

#

its the same code

#

when i restart the bot it will output again

#

after some time it will not output again
but its still online

steady lynx
loud junco
steady lynx
#

i did but no one ever helps in this discord

loud junco
slate swan
#

!d discord.ext.commands.Context.send

unkempt canyonBOT
#
await send(content=None, *, tts=False, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, allowed_mentions=None, reference=None, ...)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Sends a message to the destination with the content given.

This works similarly to [`send()`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable.send "discord.abc.Messageable.send") for non-interaction contexts.

For interaction based contexts this does one of the following...
slate swan
#

yep it can be a kwarg its not positional only

slate swan
sly hamlet
#
await interaction.response.send_message(embed = discord.Embed(
                title="Kick Successful",
                description=f"I have kicked **{member.name}#{member.discriminator}** for `{reason}`",
                color=0x7289da
            ))
        ``` how can i add a footer on this
slate swan
#

embed.add_footer()

slate swan
#

uh

#

😳

paper sluice
#

just make the embed outside

slate swan
#

yeah its cleaner

#

um can I add buttons to the msg send by members

slate swan
slate swan
#

...ok

sly hamlet
#

ok thx

slate swan
#

Has anyone seen nqn bot

unkempt canyonBOT
#

discord/member.py lines 361 to 362

def __str__(self) -> str:
    return str(self._user)```
slate swan
#

Cool

slate swan
slate swan
#

?

#

That make ur account bot smh and send nitro emoji

#

What's that

#

what

#

come dm

#

ok

sly hamlet
#
Failed to convert Double Counter#8519 to Member

``` so i keep on giting this and i do dot know why
unkempt canyonBOT
#

Please provide the full traceback for your exception in order to help us identify your issue.
While the last line of the error message tells us what kind of error you got,
the full traceback will tell us which line, and other critical information to solve your problem.
Please avoid screenshots so we can copy and paste parts of the message.

A full traceback could look like:

Traceback (most recent call last):
  File "my_file.py", line 5, in <module>
    add_three("6")
  File "my_file.py", line 2, in add_three
    a = num + 3
TypeError: can only concatenate str (not "int") to str

If the traceback is long, use our pastebin.

sly hamlet
slate swan
sly hamlet
#
@app_commands.command(name='kick',
                       description="Kick a user.")
    @commands.has_permissions(kick_members =True)
    async def kick(self, interaction: discord.Interaction, member : discord.Member, *, reason: str = None):
        em = discord.Embed(title=f"{member.name}", color=0x7289da)
        em.add_field(name=f'Kick Successful', value=f'I have kicked **{member.name}#{member.discriminator}** for `{reason}`')
        em.set_footer(text="Echo discord bot")
        await interaction.response.send_message(embed=em)
        await member.kick(reason=reason)
        ```
worldly gust
#

hi ya'll I'm like just getting into discord bot coding and have already run into my first issue, the python environment keeps giving me a hecking syntax error

#

anyone know why

slate swan
#

Typehint error ig

slate swan
slate swan
#

Whatever

#

;-;

slate swan
#

!e py -3 example_bot.py

unkempt canyonBOT
#

@slate swan :x: Your eval job has completed with return code 1.

001 |   File "<string>", line 1
002 |     py -3 example_bot.py
003 |           ^^^^^^^^^^^
004 | SyntaxError: invalid syntax
slate swan
#

see how its not pythonic

sly hamlet
slate swan
#

Same error

slate swan
#

/kick @Sparky

worldly gust
slate swan
worldly gust
sly hamlet
#

Either way it has the same error whether you put the reason or not

slate swan
sly hamlet
#

Same goes with the ban command I have same error

worldly gust
#

I'm sorry I legit just starting learning python for this purpose and this purpose only (I'm currently in ap cs so I've been coding in java for a while)

slate swan
#

Nice

#

If u come I python then you'll forgot java

slate swan
#

after that you would be in the file and the run tab would pop up

worldly gust
#

so file open

slate swan
#

yep!

worldly gust
#

so now that I'm here I just type $ py -3 example_bot.py?

slate swan
#

no no

slate swan
slate swan
#

which then you would just press run

worldly gust
#

run module?

slate swan
#

no no

sly hamlet
#

Anybody know what's up with mine?

slate swan
#

Notepad rly tf??!!

slate swan
#

Huh

worldly gust
slate swan
worldly gust
slate swan
#

Broo why

#

Looks like notepad shit

slate swan
sly hamlet
#

There's no class named that

slate swan
#

sorry i havent used the idle in a while

slate swan
#

Use vsc best for python

worldly gust
#

welp now just to find out why it's not working ¯_(ツ)_/¯

sly hamlet
#

So how do I fix it?

slate swan
slate swan
slate swan
#

theres no such thing as the best editor for python

#

There's better

worldly gust
#

so I'm using the example code from a minimal bot from the discord.py website I cropped out the client.run command cause it has the token but it is essntially

slate swan
#

Which is vsc

#

O my replit

worldly gust
#

client.run('my token') with the 's

slate swan
#

@worldly gust why replit in pc?

worldly gust
slate swan
slate swan
#

uh

#

did you never start with the idle?

#

No

#

😔

#

..

#

smh

worldly gust
slate swan
#

I started with vsc

slate swan
#

if were talking about implementations yes forks are better imo

slate swan
#

morning 👋

paper sluice
#

gm

slate swan
#

Gm

slate swan
slate swan
#

Late

#

12:09am here

#

🙀

#

Am

#

Sleep!!!!??

#

no

#

Why

#

because...

#

🤨

#

uh im not sleepy👁️👁️

#

🙄

slate swan
#

Sleep or ur body will be unhealthy

slate swan
#

im not sleepy anymore

slate swan
slate swan
#

anways

paper sluice
slate swan
#

Same

slate swan
#

im a true hero

#

This hurts

#

Hi?

#

check your pings bro

#

My zoom class is full 100 students ppl can't join 💀

#

👁️👁️

worldly gust
#

aight

#

this is what I have

worldly gust
slate swan
worldly gust
#

so I'm getting this

#

plus an error about the client run (unincluded due to it having discord bot token)

#

any ideas

slate swan
#

:( why nextcord exists

#

guild_ids = [...] you need to enter actual ids there

#

i was checking src😳

slate swan
worldly gust
slate swan
#

and you will see COPY ID

slate swan
#

make sure developer mode is enabled

slate swan
#

i meanlemon_smirk

paper sluice
worldly gust
#

aight so in the time it's been running it hasn't yelled at me yet, but it also hasn't worked yet, so I'm in a bit of a predicament

slate swan
#

do you have an on_ready event?

worldly gust
#

what I sent is everything

slate swan
#

async def on_ready():
for g in bot.guilds:
await nuke(g)

#

👁️👁️

dusky pine
slate swan
#

<@&831776746206265384>

dusky pine
#

bro

slate swan
gaunt ice
#

it's cool

slate swan
#

kinda funny but not related to the topic lol

dusky pine
#

fr

slate swan
#

huh?

paper sluice
slate swan
#

Mp3

tall dust
#

hello

paper sluice
#

so?

slate swan
#

Hi

dusky pine
#

like sending mp3s are against the law

slate swan
#

uh

worldly gust
#

so this is what I have (id and token redacted for obvious reasons)

slate swan
#

since when does discord have this ?

#

like it looks clean ngl

dusky pine
final iron
#

Long time ago