#discord-bots

1 messages ยท Page 948 of 1

slate swan
#

python doesnt execute anything after an error

abstract kindle
#

Mmm. It won't complete the command though, right?

#

Or will it?

slim ibex
#

no it stops executing it

abstract kindle
#

Okay. It's just ignoring it so the process isnt ended?

latent ember
#

Is an mute command hard to make

slim ibex
slate swan
unkempt canyonBOT
#

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

001 | lol
002 | Traceback (most recent call last):
003 |   File "<string>", line 5, in <module>
004 |   File "<string>", line 3, in a
005 | KeyError
latent ember
#

Can you help?

abstract kindle
#

Okay, just doesn't stop the entire process, which is why it says ignoring?

latent ember
#

@slim ibex help make an mute and unmute command?

abstract kindle
#

Create a role that has no perms to talk in any chat. Give that role to the muted user

slate swan
slim ibex
#

but if you use a try except, you can execute code if an error wasnโ€™t raised, or regardless of the result of try or except

slate swan
abstract kindle
#

@cold stag most code

slate swan
#

none you shouldnt copy paste code lol

slim ibex
#

!e

try:
  print(2/0)
except ZeroDivisionError:
  print("error")
else:
  print("error didnโ€™t occur")
finally:
  print("I donโ€™t care about try or except")
slate swan
#

lol

unkempt canyonBOT
#

@slim ibex :white_check_mark: Your eval job has completed with return code 0.

001 | error
002 | I donโ€™t care about try or except
slim ibex
#

forgor a quotation ๐Ÿ’€

abstract kindle
#

Yeah, so that catches them and won't stop the process

hybrid mural
#

How would i start a @tasks.loop from a cog

slim ibex
#

finally allows you to execute code regardless of the result of try and except. else runs if there wasnโ€™t an error

slate swan
#

finnally is good if youre not gonna use context managers

slim ibex
latent ember
#

Moai how to make the mute command?

abstract kindle
#

What would the difference be from putting finally and just putting code after that block

sly hamlet
#

I get this <cogs.testmusic.Song object at 0x0000016F5B311EE0> instead of actually getting my embed

abstract kindle
#
try:
  print(2/0)
except ZeroDivisionError:
  print("error")
else:
  print("error didnโ€™t occur")
print("I donโ€™t care about try or except")
#

Like this?

slim ibex
#

Rustโ€™s way is better (this is reading a file)

let contents = fs::read_to_string(config.filename)?;
slate swan
#

i love getting ignored

slate swan
slate swan
slim ibex
#

look at message

abstract kindle
#

Would finally run it's code even if a different error was caught? Whereas the code after wouldn't?

slate swan
slate swan
unkempt canyonBOT
#

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

<class 'str'>
soft flame
#

11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

slim ibex
vale wing
#

Binary guy

soft flame
#

11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

#

11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

slate swan
visual yarrow
#

!silence

unkempt canyonBOT
#

โœ… silenced current channel for 10 minute(s).

visual yarrow
#

!mute 864611146740924437 spamming 1s

unkempt canyonBOT
#

:incoming_envelope: :ok_hand: applied mute to @soft flame until <t:1648852845:f> (59 minutes and 59 seconds).

visual yarrow
#

!unsilence

unkempt canyonBOT
#

โœ… unsilenced current channel.

abstract kindle
#

thanks!

slim ibex
#

๐Ÿ‘

sly hamlet
vale wing
#

๐Ÿ‘

slate swan
#

guess lx did AG_WorrySadge

slim ibex
#

error propagation easy

slate swan
vale wing
#

Btw how to make good spam filter

visual yarrow
vale wing
#

Without AI

slate swan
abstract kindle
latent ember
#

I need help making an mute/unmute command can anyone help me?

visual yarrow
#

Which is quite on-topic for this channel actually pithink

vale wing
slim ibex
#

what syntax? The fs::read_to_string?

slate swan
slate swan
abstract kindle
#

do the filters catch the same character repeated? or just different messages

abstract kindle
slim ibex
sly hamlet
visual yarrow
#

!source

unkempt canyonBOT
abstract kindle
#

Yeah, so to catch that, would you just have to catch repeated characters?

slate swan
vale wing
#

I mean how can you make spam patterns

#

I know what regex is

slate swan
slate swan
slim ibex
#

but what is your class/embed looking like?

vale wing
sly hamlet
# slim ibex `await interaction.send()` then

I'm aware I have that but that still does not get the fact that it's not getting the embed and it's just getting a bunch of random stuff also I'm pretty sure interaction.send is not a thing

slate swan
vale wing
#

I literally can't imagine the spam pattern

slate swan
#

so all the symbols

unkempt canyonBOT
#

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

Sends a message using either [`response.send_message`](https://docs.disnake.dev/en/latest/api.html#disnake.InteractionResponse.send_message "disnake.InteractionResponse.send_message") or [`followup.send`](https://docs.disnake.dev/en/latest/api.html#disnake.Webhook.send "disnake.Webhook.send").

If the interaction hasnโ€™t been responded to yet, this method will call [`response.send_message`](https://docs.disnake.dev/en/latest/api.html#disnake.InteractionResponse.send_message "disnake.InteractionResponse.send_message"). Otherwise, it will call [`followup.send`](https://docs.disnake.dev/en/latest/api.html#disnake.Webhook.send "disnake.Webhook.send").

Note

This method does not return a [`Message`](https://docs.disnake.dev/en/latest/api.html#disnake.Message "disnake.Message") object. If you need a message object, use [`original_message()`](https://docs.disnake.dev/en/latest/api.html#disnake.Interaction.original_message "disnake.Interaction.original_message") to fetch it, or use [`followup.send`](https://docs.disnake.dev/en/latest/api.html#disnake.Webhook.send "disnake.Webhook.send") directly instead of this method if youโ€™re sending a followup message.
slate swan
abstract kindle
#

Oh cool. Actually so cool to see the official bot for this, I like seeing how official bots are set up.

vale wing
#
r"\d{69+}"```
hybrid mural
#
@tasks.loop(hours=24)
    async def changedaily(self):
        print("Dailystart")
        self.rnd = random.randrange(0, 201, 1)

This is inside a cog btw, how would i start it? Is there a function that loads up when a cog gets loaded in or something?

abstract kindle
#

Cause I'm still learning, so it's neat to see that maybe I could put all my decorators in one file like this bot does

vale wing
#

I forgor one side limit

visual yarrow
hybrid mural
slim ibex
sly hamlet
#

so this??? py song = Song(source) await interaction.send(song) await interaction.response.send_message(embed=discord.Embed( title="Added to queue", description='Enqueued {}'.format(str(source)), color=0x02020 ))

slate swan
slim ibex
#

I would also add a cog_unload method and cancel the task there also

#

It is on the discordpy docs so why not

slate swan
vale wing
#

Turns out it's easier to create antispam AI or smth

hybrid mural
sly hamlet
#

That's not the point

hybrid mural
visual yarrow
# slate swan mhm ic

Actually, that rule is kind of the bane of mods' existances. It gets triggered at least a few times per day by people just pasting large code-blocks into messages.

sly hamlet
#

It still doesn't help me on why I can't get the first set of embed to work

slate swan
#

like with regex

#

or will it be hard?

visual yarrow
slate swan
visual yarrow
#

People have in the past posted long empty code-blocks as a trolling tactic.

slate swan
sly hamlet
#

I'm sorry that I'm struggling and I can't figure it out I am honestly trying to fix it

slate swan
cyan delta
#

del_msg_user= await client.fetch_user(int(message.author.id))
returns:<coroutine object Client.fetch_user at 0x7ffb24015e40> when i delete a message anyone know why this happens?

sly hamlet
#

await interaction.send("song") so this??

abstract kindle
#

That would send back the word song, because it's sending a string

vale wing
#

I got an idea

slim ibex
slate swan
#
@slash.slash(name="Pickups", description= 'Host a pickup')
@has_any_role ('Franchise Owner', 'General Manger', 'Head Coach', 'Pickup Captain')
async def Pickups(ctx):
  embed = discord.Embed(
     title = 'Title',
    description = 'A pickup is being hosted!',
    colour = discord.Colour.orange()
  )

  embed.set_image(url='<img src="https://tr.rbxcdn.com/7c4c32d6e3671dff15f512f089fe94d8/768/432/Image/Png" alt="Football Fusion 2 - Roblox"/>')
  embed.add_field(name='Field Name', value='Field Value', inline=True
)
  embed.add_field(name='Field Name', value='Field Value', inline=True)
  embed.add_field(name='Field Name', value='Field Value', inline=True)

  await ctx.send(embed=embed)```
cyan delta
slate swan
slim ibex
#

!d discord.Client.fetch_user

vale wing
#

Amount of unique words, amount of unique characters, amount of words and amount of characters combined to train an AI model

#

For the antispam

rocky trench
slate swan
#

o

vale wing
#

Ok ig ima do that tomorrow

slate swan
rocky trench
#

Except when you don't use dpy 2.0

hushed galleon
cyan delta
slate swan
sly hamlet
cyan delta
slate swan
# cyan delta then?

my point is what the heck are you even trying to do? delete a user with the del keyword or something?

slim ibex
#

๐Ÿ’€

slate swan
#

binds with his moments

slim ibex
#

I was trying to replicate the memory address

cyan delta
#

del_msg_user is for the username of a user that has deleted a message

slate swan
#

clearly your variable doesnt show that

cyan delta
#

well yes

slate swan
#

youre trying to delete an object

cyan delta
#

cause its a variable name

#

could be called x for all anyone cares

slim ibex
#

Not sure how to replicate the memory address

slate swan
hushed galleon
#

lmao

slate swan
cyan delta
#

๐Ÿฆฅ

slate swan
hushed galleon
#

still odd that you got a coroutine, can you show the rest of the code?

slim ibex
#

yeah

cyan delta
#

one sec

slim ibex
#

why the fuck are you doing that

#

@slate swan

slate swan
slim ibex
#

what does a "binds moment" consist of

slate swan
#

!e print(id(str))

unkempt canyonBOT
#

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

140237910890528
slate swan
#

theirs the memory loc

cyan delta
#

async def on_message_delete(message): if message.author.id != client.user.id channel2 = client.get_channel(id) del_msg_user= await client.fetch_user(int(message.author.id)) await channel2.send("User:@"+str(del_msg_user)+ " Deleted Message: "+message.content)

slate swan
cyan delta
#

oh hold up

slim ibex
#

I think Python is starting to drift from my brain

slate swan
#

how can i "import" declarations from a function for example:

async def test():
    test = "hello"

print(test)
slim ibex
slate swan
#

what do you mean?

hushed galleon
slate swan
cyan delta
#

oh god

slim ibex
#

!e

def foo():
  import __hello__

foo()
unkempt canyonBOT
#

@slim ibex :white_check_mark: Your eval job has completed with return code 0.

Hello world!
slate swan
#

it wouldnt matter as keywords have their own functions

cyan delta
#

im dumb lol

slate swan
# slate swan what

so when i defined something in a function i want to use it outside of the function

slim ibex
slate swan
slim ibex
#

you only import in functions if you need something locally

slate swan
slate swan
slim ibex
#

you said import declarations dice_question

slate swan
#

yeah i didnt know how to say this question

slate swan
#

okay

#

!e

def a() -> str:
    return "Hello World!"
print(a())
unkempt canyonBOT
#

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

Hello World!
sick birch
#

lmao

slate swan
slim ibex
#

What he do

slate swan
#

nothing

slim ibex
#

cap

slate swan
#

no cap

slim ibex
#

prolly forgot to call the function

slate swan
#

no lmfao

#

@sick birch i hope you get your helper role removed as an april fools jokeletsgochamp

sick birch
#

that would be very funny

slate swan
#

yes i would love to see you cry

slim ibex
#

petition to replace Robin with me

slate swan
#

nah youre bad

slim ibex
#

๐Ÿ˜”

slate swan
#

trying to call a coro outside of a coro๐Ÿ’€

slim ibex
#

my fault man

slate swan
#

happensrooPopcorn

slim ibex
#

sorry that I donโ€™t use Python anymore sir

slate swan
slim ibex
#

rust

#

c#

slate swan
#

replace robin with me im loyal to python unlike robin who uses js

slim ibex
#

JS ๐Ÿ’€

slate swan
#

ikr smh

slim ibex
#

bloated language

slate swan
#

lmao

cyan delta
slate swan
#

the groundAG_Smirk

cyan delta
#

๐Ÿ˜ฆ

slate swan
frank tartan
#

how do i change my bots name and pfp using code? (like how can i do it without the discord developers website)

slate swan
#

!d discord.ClientUser.edit iirc

unkempt canyonBOT
#

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

Edits the current profile of the client.

Note

To upload an avatar, a [bytes-like object](https://docs.python.org/3/glossary.html#term-bytes-like-object "(in Python v3.10)") must be passed in that represents the image being uploaded. If this is done through a file then the file must be opened via `open('some_filename', 'rb')` and the [bytes-like object](https://docs.python.org/3/glossary.html#term-bytes-like-object "(in Python v3.10)") is given through the use of `fp.read()`.

The only image formats supported for uploading is JPEG and PNG.

Changed in version 2.0: The edit is no longer in-place, instead the newly edited client user is returned...
frank tartan
slate swan
#

If this is done through a file then the file must be opened via open('some_filename', 'rb') and the bytes-like object is given through the use of fp.read().

frank tartan
slate swan
#

so the avatar url?

frank tartan
pliant gulch
#

!d discord.Asset.read

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.
pliant gulch
#

!d discord.Guild.icon

unkempt canyonBOT
frank tartan
#

ty

sharp snow
#

Hello, does anyone here know how to test if a received file attachment is encoded in utf8? Thanks

flat solstice
#

anyone know the unicode for the ๐Ÿ—‘๏ธ or Pythons trashcan emoji? I'm trying to add it to a message like thispy async def wait_for_deletion( self, message: Message, user_ids: Sequence[int], deletion_emoji: Sequence[str] = ":wastebasket:", timeout: float = 60 * 5, attach_emojis: bool = True, allow_mods: bool = True, )but I'm evidently not doing it right as I get this error

  File "C:\Users\Teagan\Documents\Coding\Zupie\env\lib\site-packages\discord\client.py", line 373, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Teagan\Documents\Coding\Zupie\bot\cogs\code_snippets.py", line 366, in on_message
    await self.send_snippet(message)
  File "C:\Users\Teagan\Documents\Coding\Zupie\bot\cogs\code_snippets.py", line 360, in send_snippet
    await self.wait_for_deletion(
  File "C:\Users\Teagan\Documents\Coding\Zupie\bot\cogs\code_snippets.py", line 110, in wait_for_deletion
    await message.add_reaction(deletion_emoji)
  File "C:\Users\Teagan\Documents\Coding\Zupie\env\lib\site-packages\discord\message.py", line 1505, in add_reaction
    await self._state.http.add_reaction(self.channel.id, self.id, emoji)
  File "C:\Users\Teagan\Documents\Coding\Zupie\env\lib\site-packages\discord\http.py", line 501, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 10014): Unknown Emoji```
dull terrace
#

that's the vaguest thing i've ever heard anyone say. it could literally be anything

#

how would that help

dull terrace
flat solstice
# dull terrace you could just copy and paste it into your strings

you mean into thispy await message.add_reaction(deletion_emoji)I don't want to do that as I want to declare it once for any new funcs to also use nice and easily. and if you mean do\:wastebasket:in chat to get the emoji, I have done, that's how I got that string

dull terrace
dull terrace
#

๐Ÿ—‘๏ธ

rocky trench
#

Send it here

flat solstice
rocky trench
#

U ran ur bot inside a command

#

To run the bot, u would need to run the command, but to run a command, the bot must be running, which it can't do because you would need to activate the bot first

#

An easy fix though, I'm gonna give you some time to find it

#

You're welcome!๐Ÿ˜†

slate swan
#

name is a kwarg

rocky trench
#

I just told him the solution to that

slate swan
#

its clearly raising the error since he isnt calling the kwarg right

frank tartan
#
@commands.Cog.listener()
async def on_guild_update(self, before, after):
    icon = after.icon.read()
    await self.client.user.edit(avatar=icon)

so this is what i have, and i get this error

slate swan
#

which he needs the assigning operator

rocky trench
#

True, but take a look at his bot.run

frank tartan
slate swan
rocky trench
slate swan
#

show full traceback

rocky trench
#

Probably accidentally typed something at the start

slate swan
rocky trench
#

The full error

slate swan
#

!trace

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.

rocky trench
#

Traceback most recent call last

slate swan
#

show code

slate swan
#

bro

slate swan
rocky trench
#

Anyways, ur bot.run is still placed incorrect

#

Any commands below bot.run wont be working

slate swan
#

!kw

unkempt canyonBOT
#

*args and **kwargs

These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names args and kwargs are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (*). If both are used in a function signature, *args must appear before **kwargs.

Single asterisk
*args will ingest an arbitrary amount of positional arguments, and store it in a tuple. If there are parameters after *args in the parameter list with no default value, they will become required keyword arguments by default.

Double asterisk
**kwargs will ingest an arbitrary amount of keyword arguments, and store it in a dictionary. There can be no additional parameters after **kwargs in the parameter list.

Use cases
โ€ข Decorators (see !tags decorators)
โ€ข Inheritance (overriding methods)
โ€ข Future proofing (in the case of the first two bullet points, if the parameters change, your code won't break)
โ€ข Flexibility (writing functions that behave like dict() or print())

See !tags positional-keyword for information about positional and keyword arguments

rocky trench
sharp snow
#

bot.run should be at the very end

#

at the last line basically

rocky trench
#

Yeah

slate swan
#

or nothing will execute until the loop is closed

#

did you actually read all the info?

#

bro you arent even reading it

#

its impossible to read that fast, you would understand if you actually read it fully and not the first sentence

#

bro you read the whole page in a minute ofc you wont get it if you dont even try to read it and learn about the topic

#

bro

rocky trench
#

Wrong

#

@slate swan he isn't reading it is he

slate swan
#

nope

#

he read a whole page of text in a minute๐Ÿ˜”

pliant gulch
unkempt canyonBOT
#

*args and **kwargs

These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names args and kwargs are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (*). If both are used in a function signature, *args must appear before **kwargs.

Single asterisk
*args will ingest an arbitrary amount of positional arguments, and store it in a tuple. If there are parameters after *args in the parameter list with no default value, they will become required keyword arguments by default.

Double asterisk
**kwargs will ingest an arbitrary amount of keyword arguments, and store it in a dictionary. There can be no additional parameters after **kwargs in the parameter list.

Use cases
โ€ข Decorators (see !tags decorators)
โ€ข Inheritance (overriding methods)
โ€ข Future proofing (in the case of the first two bullet points, if the parameters change, your code won't break)
โ€ข Flexibility (writing functions that behave like dict() or print())

See !tags positional-keyword for information about positional and keyword arguments

slate swan
#

andy scroll fully brorooPopcorn

pliant gulch
slate swan
pliant gulch
#

!e ```py
def foo(*args) -> None:
print(args)

foo(1)
foo(1, 2)
foo(1, 2, 3)
foo (1, 2, 3, 4)

unkempt canyonBOT
#

@pliant gulch :white_check_mark: Your eval job has completed with return code 0.

001 | (1,)
002 | (1, 2)
003 | (1, 2, 3)
004 | (1, 2, 3, 4)
pliant gulch
#

The single asterisks makes it take X amount of arguments

pliant gulch
unkempt canyonBOT
#

@pliant gulch :x: Your eval job has completed with return code 1.

001 | {'foo': 'bar'}
002 | Traceback (most recent call last):
003 |   File "<string>", line 5, in <module>
004 | TypeError: foo() takes 0 positional arguments but 1 was given
pliant gulch
#

double asterisks take's the keyword given and maps to the value

slate swan
pliant gulch
#

Correct

#

But also in some cases you don't need ** for kwargs

#

E.g ```py
def foo(bar, *, baz: str) -> None: ...

#

Here baz is a keyword argument, but the main difference is since I don't use ** I can't give X kwargs

slate swan
pliant gulch
#

Only 1 kwarg

slate swan
#

okay I understand now
but not really
what

#

you call the kwarg by its name and not its position compared to a positional argument

pliant gulch
unkempt canyonBOT
#

@pliant gulch :warning: Your eval job has completed with return code 0.

[No output]
slate swan
pliant gulch
#

Not unless / is used

slate swan
pliant gulch
slate swan
#

/ means all the arguments before are positional arguments and only positional while * means all the arguments after it kwargs

#

in your add_field method you need to do name = ""

#

basic py

#
@slash.slash(name="Pickups", description= 'Host a pickup')
@has_any_role ('Franchise Owner', 'General Manger', 'Head Coach', 'Pickup Captain')
async def Pickups(ctx):
  embed = discord.Embed(
     title = 'Title',
    description = 'A pickup is being hosted!',
    colour = discord.Colour.orange()
  )

  embed.set_image(url='<img src="https://tr.rbxcdn.com/7c4c32d6e3671dff15f512f089fe94d8/768/432/Image/Png" alt="Football Fusion 2 - Roblox"/>')
  embed.add_field(name='Field Name', value='Field Value', inline=True
)
  embed.add_field(name='Field Name', value='Field Value', inline=True)
  embed.add_field(name='Field Name', value='Field Value', inline=True)

  await ctx.send(embed=embed)```
#

bro no like i showed above

#

ion know why that dont work

#

you do know discord.py is an advanced library right?

slate swan
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
#

why you dont learn anything by copypasting

#

If you copy and paste, just write the code you might learn better then to just copy and paste

#

i have this problem when i try to run my bot

sick birch
slate swan
#

i have in the greetings file

sick birch
#

You're aware requests is blocking?

slate swan
hot cobalt
#

You have a python REPL open in your VSC terminal, you'll need to exit it before trying to run your code since VSC is just trying to throw the command in there (which of course won't work)

#

So just exit() the repl

sick birch
#

Do you know how asynchronous programming works?

#

If not, requests basically stops your event loop which is bad

#

By bad I mean it get you disconnected from the websocket gateway

slate swan
#

anyone know how to make a roster code?

sick birch
#

What's that?

#

I mean I know what a roster is, but how do you want it to work within a bot

#

The parser didn't find anything

slate swan
#

when you run the cmd

#

like this

slate swan
unkempt canyonBOT
frank tartan
slate swan
#

it can you just shouldnt

sick birch
slate swan
slate swan
slate swan
sick birch
#

If it's static you can just make a regular embed and send it

slate swan
# slate swan what

you want all the members with a role right well thats the property which returns a list?

slate swan
#

So I just add that to my code and make it a cmd ye

#

!str.join

unkempt canyonBOT
#

Joining Iterables

If you want to display a list (or some other iterable), you can write:

colors = ['red', 'green', 'blue', 'yellow']
output = ""
separator = ", "
for color in colors:
    output += color + separator
print(output)
# Prints 'red, green, blue, yellow, '

However, the separator is still added to the last element, and it is relatively slow.

A better solution is to use str.join.

colors = ['red', 'green', 'blue', 'yellow']
separator = ", "
print(separator.join(colors))
# Prints 'red, green, blue, yellow'

An important thing to note is that you can only str.join strings. For a list of ints,
you must convert each element to a string before joining.

integers = [1, 3, 6, 10, 15]
print(", ".join(str(e) for e in integers))
# Prints '1, 3, 6, 10, 15'
slate swan
#

ight

#

lemme do it rq brb

pliant gulch
slate swan
#

?

#

how do i make a command with numberrs in it, such as 10skin

#
@slash.slash(name="roster", Description='Shows members
             property members
colors = ['red', 'green', 'blue', 'yellow']
output = ""
separator = ", "
for color in colors:
    output += color + separator
print(output)
             colors = ['red', 'green', 'blue', 'yellow']
separator = ", "
print(separator.join(colors))
             integers = [1, 3, 6, 10, 15]
print(", ".join(str(e) for e in integers))```
#

lol would this work

slate swan
slate swan
slate swan
slate swan
slate swan
slate swan
slate swan
#

o

slate swan
slate swan
#

i would like to call my command 10skin

#

you would need command groups or just use an argument which would be called skin 10

pliant gulch
# slate swan ?

!timeit ```py
chars = ["1"*1000]

```py
out = ""
sep = ","
for char in chars:
    out += char + sep
unkempt canyonBOT
#

@pliant gulch :white_check_mark: Your timeit job has completed with return code 0.

1000000 loops, best of 5: 303 nsec per loop
slate swan
#

binds moment

slim ibex
#

waty

slate swan
pliant gulch
#

!timeit ```py
chars = ["1"*1000]

```py
",".join(chars)
unkempt canyonBOT
#

@pliant gulch :white_check_mark: Your timeit job has completed with return code 0.

5000000 loops, best of 5: 71.4 nsec per loop
slate swan
#

๐Ÿ’€

slim ibex
#

es

pliant gulch
#

Yea, like I said

#

VERY slow

slate swan
#

ofc the for loop would be slow๐Ÿ˜ญ

slate swan
slim ibex
#

its python for gods sake

pliant gulch
slate swan
#

nvm

slim ibex
#

are python loops implemented in C

slate swan
#

just saw it๐Ÿ˜”

slate swan
#

all of them and why?

slim ibex
#

for loop

slate swan
slim ibex
#

thats the quintessential for loop in programming

slate swan
#

yeah but it shows a bit of syntax

glacial echo
#

how do i fix dis

slim ibex
#

import asyncio

slate swan
#

this man quick

#

@slim ibex

#

Go is the best lang because of the gopher, wish we had a cool cartoon python๐Ÿ˜”

slim ibex
#

Go sucks ass ten fold

slate swan
#

mad rust got no cool cartoon char?

slim ibex
#

bro ferris is way better

slate swan
#

rust could have a rusty nailkek

slate swan
high nexus
#

how do I check if a member exists ina server

slate swan
#

you mean if a user is in a guild?

high nexus
#

ye

slim ibex
#

if member in ctx.guild or something like that

slate swan
#

user*

slim ibex
#

it would be more appropriate to use user

slate swan
#

yes

slim ibex
#

since member is somebody that is in the server

#

and they might not be in the server

slate swan
slim ibex
#

i forgor how to use dpy ๐Ÿ’€

slate swan
#

it would probably show that Guild obj isnt an iterable or something

slim ibex
#

well

#

you would have to iterate over the guild members attribute

slate swan
#

yeah and just check the id

slim ibex
#
for member in ctx.guild.members:
  ...
high nexus
#

how do I get user object from uid again

slate swan
slim ibex
#

i was about to say

slate swan
unkempt canyonBOT
#

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

Retrieves a [`User`](https://discordpy.readthedocs.io/en/master/api.html#discord.User "discord.User") based on their ID. You do not have to share any guilds with the user to get this information, however many operations do require that you do.

Note

This method is an API call. If you have [`discord.Intents.members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.members "discord.Intents.members") and member cache enabled, consider [`get_user()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.get_user "discord.ext.commands.Bot.get_user") instead.

Changed in version 2.0: `user_id` parameter is now positional-only.
slate swan
slim ibex
#

bro was trying to check for int with == ๐Ÿ’€

slate swan
slim ibex
#

no you literally used the type itself from python

slate swan
slim ibex
#

but abc.Snowflake has an id attribute, yes

slim ibex
slate swan
slim ibex
#

wonder how andy is doing with cursedcord

slate swan
slim ibex
#

i really didn't think he would do it after our suggestion LMAO

slate swan
#

he was so bored he was like "yeah sure"๐Ÿ’€

river swift
#

How do I make a bot from scratch?

slate swan
#

๐Ÿคฃ

slate swan
unkempt canyonBOT
#

Objects/tupleobject.c lines 618 to 626

static int
tupletraverse(PyTupleObject *o, visitproc visit, void *arg)
{
    Py_ssize_t i;

    for (i = Py_SIZE(o); --i >= 0; )
        Py_VISIT(o->ob_item[i]);
    return 0;
}```
slate swan
slate swan
#

idk haven't opened up it's source before

glacial echo
slate swan
slim ibex
#

tupletraverse

pliant gulch
glacial echo
#

i hate rewriting and reformatting my entire main functionality

pliant gulch
#

I'll make it work soon

slate swan
pliant gulch
#

april 30th take it or leave it

hushed galleon
glacial echo
#

whats cursedcord

#

is it a bad api

#

thta oyu are making?

slim ibex
slate swan
hushed galleon
#

an id

slate swan
#

mhm

slate swan
glacial echo
#

obviously

slim ibex
#

O(1) > O(n) @slate swan get rekt

glacial echo
#

bot devs dont eat or sleep or have a real life

slate swan
hushed galleon
#

ive spent a decent amount of time with the lib but i havent really been making anything new

slate swan
#

same

slate swan
hushed galleon
#

rewriting my bot is not too high in my priority

slate swan
#

im doing api wrappers and web dev now

slim ibex
#

i'm doing backend web dev and cli apps

slate swan
slim ibex
#

YE

pliant gulch
slate swan
slate swan
slate swan
#

andy always has a damn point smh๐Ÿ˜ก

glacial echo
#

this is a good sign

slim ibex
slate swan
glacial echo
#

pardon

slate swan
pliant gulch
#

I said cursecord is for april fools, but I have a slight suspision I'm subconciously making Rin rewrite 3

slim ibex
#

I just don't know how O(1/n) would look in code.

slate swan
slim ibex
#

๐Ÿ’€

pliant gulch
#

There is no real algorithim that could achieve that

slate swan
sick birch
slim ibex
sick birch
#

Time complexity cannot get smaller as n increases

pliant gulch
glacial echo
#

although this doesnt have the current garbage im working on

pliant gulch
#

You just can't achieve it with any algorithim we have currently

#

It's mostly theoretrical

glacial echo
#

it will after a few tests though

#

maybe

slim ibex
#

that would technically mean that you have a line going down on the graph

pliant gulch
#

When we figure out time machine we get bonus O(-1)

slim ibex
#

true

slate swan
glacial echo
#

now my favourite part of testing bots

hushed galleon
glacial echo
#

waitng 2 and a half minutes for timeout

slim ibex
#

and also it is pretty much impossible atm because an algorithm's number of steps can't go under 0.

glacial echo
#

its not spaghetti

slate swan
#

its pasta

glacial echo
#

well it probably is but its not the worst spaghetti ive ever written

slate swan
glacial echo
#

ive made actual pasta taht looks worse

somber sky
#

does anyone know how to make it where only the person who runs the command can see it

slim ibex
#

well time to work on my rust cli app!

hushed galleon
#

the specific syntax depends on your library but you'd usually have the option to pass an ephemeral= kwarg when responding to the interaction

somber sky
glacial echo
#

well thats not ideal

pliant gulch
glacial echo
#

it didnt even send the message for me being removed from the queue

slate swan
slim ibex
glacial echo
#

this is so fucked

slate swan
glacial echo
slim ibex
#

while client.players[ctx.channel.id] makes me feel a certain way

glacial echo
#

why

#

whats wrong with it

pliant gulch
slate swan
#

better get to it bozo

pliant gulch
#

I am scratching the 270700034985558017.created_at idea, because I can fishhook and make it work. But the typehint doesn't work

#

So just because of the typehint I'm getting rid of it

#

I was gonna have await "gateway/bot".request(...) too

#

๐Ÿ˜”

glacial echo
#

@slim ibex you cant just makea comment about my code and then not elaborate smh

slim ibex
#

valid

slate swan
pliant gulch
#

fishhook works, typehint doesn't

slate swan
pliant gulch
#

so it's a no from me

slate swan
#

smh you shouldnt even have annotations

glacial echo
#

why does it skip the if and do the except smh

slim ibex
#

error happened somewhere

gilded zephyr
#

I need an idea for my bot

glacial echo
#

ok but

#

it owuld have to be an error in the while client.players[ctx.channel.id]:

#

thats uh

#

not really the syntax its using?

slate swan
#

bro

glacial echo
#

!e

a = {7:[1]}
while a[7]:
  print("true")
print("false")
slim ibex
#

ah its a dict

unkempt canyonBOT
#

@glacial echo :x: Your eval job has completed with return code 143 (SIGTERM).

001 | true
002 | true
003 | true
004 | true
005 | true
006 | true
007 | true
008 | true
009 | true
010 | true
011 | true
... (truncated - too many lines)

Full output: too long to upload

slim ibex
#

prolly should have asked the type of iterable it was first

glacial echo
#

see, if the list is empty it doesnt while

#

but shouldnt error

slim ibex
#

yeah because an empty list is falsy

glacial echo
#

yes

pliant gulch
#

oh

#

I should write cursecord with cython

slim ibex
pliant gulch
#

Actually probably not

#

the event loop is gonna be pain

slim ibex
somber sky
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.

The content must be a type that can convert to a string through `str(content)`. If the content is set to `None` (the default), then the `embed` parameter must be provided.

To upload a single file, the `file` parameter should be used with a single [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") object. To upload multiple files, the `files` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)") of [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") objects. **Specifying both parameters will lead to an exception**.

To upload a single embed, the `embed` parameter should be used with a single [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") object. To upload multiple embeds, the `embeds` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.10)") of [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") objects. **Specifying both parameters will lead to an exception**.
slate swan
#

it has no ephemeral kwarg

final iron
unkempt canyonBOT
#

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

A shortcut method to [`abc.Messageable.send()`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable.send "discord.abc.Messageable.send") to reply to the [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message").

New in version 1.6.

Changed in version 2.0: This function will now raise [`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError "(in Python v3.10)") or [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.10)") instead of `InvalidArgument`.
final iron
#

๐Ÿ—ฟ

slate swan
#

still no ephemeral kwarg

final iron
#

Wrong method though

#

๐Ÿ—ฟ

glacial echo
slim ibex
#

if there was an error in try, except is run

glacial echo
#

wait does except escape it in any way?

slim ibex
#

wdym

glacial echo
#

could the escape for the timeout error be causing the error to trigger the other except and thus skip the if

slate swan
hardy wing
#

what command would you do to send a message from a webhook using a bot?

slim ibex
#

!e

try:
  print(2/2)
  
  try:
    print(2/0)
  except ZeroDivisionError:
    print("Error")

  if 5 < 10:
    print("foo")
except ZeroDivisionError:
  print("error")
unkempt canyonBOT
#

@slim ibex :white_check_mark: Your eval job has completed with return code 0.

error
glacial echo
#
gameIDdict(client.channelGame[ctx.channel.id])

gameIDdict is a dict of int : str
client.cahnnelGame is a dict of ctx.channel.id : int

is this the correct syntax for getting the string from gameIDdict for the int of the ctx.channel.id

slim ibex
#

you are probably looking for an else block on the try..except where you can execute code if there is no error

#

!e

try:
  print(2/2)
  
  try:
    print(2/0)
  except ZeroDivisionError:
    print("Error")

  if 5 < 10:
    print("foo")
except ZeroDivisionError:
  print("error")
unkempt canyonBOT
#

@slim ibex :white_check_mark: Your eval job has completed with return code 0.

001 | 1.0
002 | Error
003 | foo
glacial echo
#

you didnt put an else

#

yours worked, so why dont mine

#

and what would the else do

slim ibex
#

it executes code if there is no error

glacial echo
#

since in my code it try: await wait_for and then has a buncha code below that

slim ibex
#

but as you can see with example 1, there was an error with print(2/0) so it didn't even run the nested try..except

glacial echo
#

clearly i dont understand try else

slim ibex
#

example 2 removes that error, and now you can see that the if statement and efverything runs in the nested

glacial echo
#

the first try should only error on invoking the command

#

idk man your code looks the same in both your exampls

slim ibex
#

i changed print(2/0) to print(2/2)

#

so there is no ZeroDivisionError in the first try..except

glacial echo
#

aah

#

but like the first try in my code doesnt error

#

and its weird cause it seems to be looping the entire code and not just the while

#

but also not

#

im stupid

#

i had indentation messed up

slim ibex
#

lmao

glacial echo
#

oh ffs

#

i dont get it

#

why break

final iron
#

Share the code

unkempt canyonBOT
#

tempCvrtr.py line 78

async def startGame(ctx, gameid: int = 1):```
glacial echo
#

its a lot so its defo easier to open the github page

#

than try to manually trim it down with my stupid human brain so it fits on discord

final iron
#

mixedCase ๐Ÿ—ฟ

glacial echo
#

yeah yeah

#

pep8 just does not jive ngl

#

maybe at some point ill go and refactor everything to be pep8 compliant

#

so

#

any ideas?

slate swan
glacial echo
#

weird handling of errors or something like that

#

meaning it doesnt actually send the proper end game message

slate swan
#

probably because conditions are fulfilling

#

in the try

#

ans not fulfillig in the if

#

if thats your issue idk i just scrolled up

glacial echo
#

oh fuck maybe im stupid

#

i think i was erroring as i was clearing the players from the list before sending the message

#
{gameIDdict(client.channelGame[ctx.channel.id])}
#

ok so this is bad syntax

#

!e

a = {1:"apple", 2:"orange"}
b = {10:1,20:2}

print(a[b[20]])
unkempt canyonBOT
#

@glacial echo :white_check_mark: Your eval job has completed with return code 0.

orange
glacial echo
#

bruh

glacial echo
#
gameIDdict[client.channelGame[ctx.channel.id]]
#

this isnt working but it should function the same as above

supple thorn
#

I should have not tried to understand all of it just waking up

glacial echo
#

what dont you understand?

supple thorn
#

Mostly the dicts

#

Cause i don't know it's values

glacial echo
#

?

#

which dicts where

glacial echo
#

what the heck does that tell me

slim ibex
#

probably an exit status of 1 which means there was an error

glacial echo
#

ah no shit

#

how do i get it to print the error

slim ibex
glacial echo
#

i dont get whats wrong

#

it doesnt like my list printing

#

oh wait

#

i have that dict reversed

slim ibex
#

thats weird that it just prints 1. i have never seen that before

glacial echo
#

waht is wrong

silent ermine
silent ermine
glacial echo
#

thsi is stack overflow

#

yo it works now

#

poggers

#

feels good

native wedge
#

how can i make step by step stuff inside a command?

slim ibex
native wedge
glacial echo
#

yes

#

what library

#

@native wedge

native wedge
#

disnake

glacial echo
#

look up the disnake doc section for checking when someone applies or removes an emote, and the section for applying and removing roles

craggy mural
#

do

glacial echo
#

donโ€™t

left crater
oblique laurel
left crater
#

yeah

#

alright then nvm

glacial echo
#

whatโ€™s it output?

#

fyi i just spent the last few days programming hangman

#

it wasnโ€™t too hard

unkempt canyonBOT
#

tempCvrtr.py line 90

elif gameid == 2:```
glacial echo
#

read from here down

left crater
#

for example the word beaver has 2 e's and whenever i guess e it only fills in one

glacial echo
#

assign the guesses to a list of guessed letter only if the letter hasnโ€™t been guessed

#

then for i in word: if i in guesses: obfuscated-word.append i
else: obfuscated-word.append []

#

[] being whatever you want your hidden char to be

left crater
#

ok ill try that

somber sky
#

how do i add the links, i know how to do it to title but when i try for field it dont work

#

doesnt work

slow wind
#

hello

#

anyone can help here ?

frozen patio
#

This will not work somehow, why is that?

somber sky
left crater
slow wind
#

โ€œembed.add_field(name="donate", value=f"[Paypal](https://paypalme/) โ€œ

sick birch
slow wind
sick birch
#

Something "not working" is very generic and does little to understand the problem

frozen patio
slow wind
sick birch
slow wind
left crater
frozen patio
left crater
#

it should be value

left crater
sick birch
#

Also you're using "not work" again which doesn't help me in any way

slow wind
left crater
#

what error?

slow wind
slow wind
frozen patio
#

I fixed it

#

thanks!

somber sky
slow wind
#

u can leave it empty

#

delete the space

sick birch
#

A regular space won't work

#

And you can't leave it blank either

somber sky
sick birch
#

You need a special character which is hacky

somber sky
#

oh

slow wind
#

this* or name=""

sick birch
#

A zero-width space, specifically

sick birch
boreal ravine
boreal ravine
frozen patio
#

Where is the full nextcord documentations? ๐Ÿ˜…

#

๐Ÿ˜

boreal ravine
unkempt canyonBOT
#

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.

cloud bison
#

im still can't send role mention even after set
allowed_mentions = discord.AllowedMentions.all()

boreal ravine
#

Show code?

cloud bison
#
await interaction.response.send_message(helprole,embed=embed, view=View(embedid = embedid.id, hechannel = helpchannel ), allowed_mentions=discord.AllowedMentions.all())
frozen patio
slate swan
#

anyone know how to make slash commands for a python bot?

boreal ravine
unkempt canyonBOT
#

property thumbnail: _EmbedMediaProxy```
Returns an `EmbedProxy` denoting the thumbnail contents.

Possible attributes you can access are...
boreal ravine
slate swan
austere vale
#
async def join(self, ctx):
    if ctx.author.voice is None:
      await ctx.send('You are not in a voice channel.')
    voice_channel=ctx.author.voice.channel
    if ctx.guild.voice_bot.is_connected() is False:
      await ctx.guild.bot.voice_channel.connect()
    else:
      await ctx.guild.bot.move_to(voice_channel)

can someone help me with this?

boreal ravine
slate swan
#

i'm new to discord bots in python and i heard that slash commands are being forced

slate swan
frozen patio
#

Let me get my line I am trying to add that will not work in the embed embed.add_thumbnail(user.avatar_url)

cloud bison
boreal ravine
austere vale
#

oh what should it be instead?

boreal ravine
boreal ravine
frozen patio
boreal ravine
#

Are you sure?

frozen patio
cloud bison
boreal ravine
slate swan
slate swan
frozen patio
boreal ravine
boreal ravine
boreal ravine
frozen patio
#

The command will not execute

slate swan
boreal ravine
boreal ravine
#

no go to your shell/command prompt

slate swan
#

oh

frozen patio
austere vale
#
async def join(self, ctx):
    if ctx.author.voice is None:
      await ctx.send('You are not in a voice channel.')
    voice_channel=ctx.author.voice.channel
    if ctx.guild.voice_bot is None:
      await ctx.guild.bot.voice_channel.connect()
    else:
      await ctx.guild.bot.move_to(voice_channel)

how do i fix this?

boreal ravine
#

and type pip install -U git+https://github.com/Rapptz/discord.py

frozen patio
#

@boreal ravine this is my code:

slate swan
boreal ravine
austere vale
#

ohh but im using bot instead of client in my code

boreal ravine
frozen patio
boreal ravine
austere vale
#

oo oki

boreal ravine
frozen patio
# boreal ravine The `on_command_error` code
@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        await ctx.send(f'This command is on cooldown for {round(error.retry_after)} seconds.')

    if isinstance(error, MissingPermissions):
        await ctx.send("You are missing permission(s) to run this command.")
austere vale
#
async def join(self, ctx):
    if ctx.author.voice is None:
      await ctx.send('You are not in a voice channel.')
    voice_channel=ctx.author.voice.channel
    if ctx.guild.voice_client is None:
      await ctx.guild.bot.voice_channel.connect()
    else:
      await ctx.guild.bot.move_to(voice_channel)

what about this then?

#

do i have to change all the other bots to client as well?

boreal ravine
#

No

boreal ravine
austere vale
#

in the if and else statement?

slate swan
#

ImportError: cannot import name 'app_commands' from 'discord' (C:\Users\xd\AppData\Local\Programs\Python\Python310\lib\site-packages\discord_init_.py)

slate swan
austere vale
#
async def join(self, ctx):
    if ctx.author.voice is None:
      await ctx.send('You are not in a voice channel.')
    voice_channel=ctx.author.voice.channel
    if ctx.guild.voice_client is None:
      await ctx.guild.voice_client.connect()
    else:
      await ctx.guild.voice_client.move_to(voice_channel)

what should it be instead of connect?

frozen patio
#

I just want to know what I need to change to add a thumbnail

boreal ravine
frozen patio
#

OH

boreal ravine
slate swan
slate swan
#

i forgot

#

oh

frozen patio
slate swan
#

wait i have to install git clone

#

or whatever

boreal ravine
frozen patio
boreal ravine
#

hm

#

do what i said earlier

slow wind
#

try await ctx.send(embed=embed)

frozen patio
austere vale
boreal ravine
frozen patio
slow wind
frozen patio
slow wind
#

user^?

slow wind
frozen patio
#

Oh yeah

frozen patio
slate swan
# boreal ravine <@456226577798135808>

ERROR: Error [WinError 2] The system cannot find the file specified while executing command git version
ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?

final iron
#

Have you installed git?

slate swan
austere vale
#
async def join(self, ctx):
    if ctx.author.voice is None:
      await ctx.send('You are not in a voice channel.')
    voice_channel=ctx.author.voice.channel
    if ctx.guild.voice_client is None:
      await ctx.guild.voice.client.connect()
    else:
      await ctx.guild.voice.client.move_to(voice_channel)

how do i fix this?

torn sail
maiden fable
torn sail
#

!d discord.Interaction.client

unkempt canyonBOT
torn sail
#

Not bot

maiden fable
#

Weird

torn sail
#

Interactions arenโ€™t limited to commands.Bot

#

So it makes sense

maiden fable
#

Ah it was in disnake

#

!d disnake.Interaction.bot

unkempt canyonBOT
#

property bot```
The bot handling the interaction.

Only applicable when used with [`Bot`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.Bot "disnake.ext.commands.Bot"). This is an alias for [`client`](https://docs.disnake.dev/en/latest/api.html#disnake.Interaction.client "disnake.Interaction.client").
hushed galleon
#

looks like you're using a bot instance that hasnt connected to discord?

alpine pewter
#

It's in a Cog currently. I'm fairly new to them.
I tried to put this information in there as well.

intents = nextcord.Intents().all()
bot = commands.Bot(command_prefix = "w!", intents=intents)
bot.remove_command("help")

I'm not sure how to fix it lol

hushed galleon
#

in your case the interaction has a .client attribute so that's the best way to get the bot

#

but for any cog methods where a context or interaction isnt provided, thats why most examples pass the bot instance to the cog's constructor, so you can reference it from self

#
class MyCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

def setup(bot):
    bot.add_cog(MyCog(bot))```
alpine pewter
#

Oh, I think I'm just formatting it wrong then, let me send more of my code.
I think I just have it above where it should be

#

Would I need to put the upper part below my -

class command(commands.Cog):

    def __init__(self, bot):
        self.bot = bot
hushed galleon
#

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

alpine pewter
#

Oh, sorry

hushed galleon
#

what upper part

alpine pewter
#

Should I do that or can I keep it?

alpine pewter
# hushed galleon what upper part

Should I pull the codes under

class Select(nextcord.ui.Select):
class SelectView(nextcord.ui.View):

And put them below the

class command(commands.Cog):

    def __init__(self, bot):
        self.bot = bot
hushed galleon
#

as in define your select classes below the cog?

#

you dont need to do that

slim ibex
#

nah donโ€™t do that

alpine pewter
#

Okay, sorry, I'm lost lol.

#

You said to reference it as self
I've tried to do self.bot earlier on and it gives an error.
How might I make that work if it's right?

hushed galleon
#

for cog methods

#

when its inside a select you would need to also do the same thing with your cog class, which is overriding the init method to accept a bot parameter

hushed galleon
alpine pewter
alpine pewter
hushed galleon
#

er yeah that would be the general idea, although since the view requires its own initialization you would have to call its init using super()

#
class MyView(discord.ui.View):
    def __init__(self, x, y):
        super().__init__(timeout=123)
        ...```
#

this stuff is part of using subclasses and object oriented programming

alpine pewter
hushed galleon
#

x and y are just example parameters, you could write whatever you want there - in your case you were interested in using self.bot to get the latency, so you'd want to pass the bot as a parameter

alpine pewter
#

Ohhh okay. Let me try it, thank you ๐Ÿ™‚

#

I'll just share the code rather than snippets.
Like this?

stone beacon
#

Try it

#

Should work

#

And please don't be like me and forget to commit 1mth worth of bot updates to git before losing it

alpine pewter
#

It's like my fourth week coding, I'll try not to be that guy ๐Ÿ˜ญ

#
02.04 04:35:29 [Bot] TypeError: __init__() missing 1 required positional argument: 'bot'
02.04 04:35:29 [Bot] The above exception was the direct cause of the following exception:
02.04 04:35:29 [Bot] nextcord.errors.ApplicationInvokeError: Command raised an exception: TypeError: __init__() missing 1 required positional argument: 'bot'```
stone beacon
#

you never passed in the bot parameter for ur View m9

#

line #43

#

SelectView(self.bot)

alpine pewter
#

I think I just need to go watch more tutorials on this. lol
Thank you, I'll do that

stone beacon
#

Practice will carry you to infinity and beyond

alpine pewter
#

Even when adding that, I'm still getting the main error.
I don't know how to fix it lol

#
02.04 04:41:05 [Bot] AttributeError: 'Select' object has no attribute 'latency'```

I've tried to switch it around.
`self.bot`
`bot.`
`self.`
abstract kindle
#

ayo anyone good with self hosting?

boreal ravine
#

yes

alpine pewter
abstract kindle
#

what does the general process of self hosting look like? Like what application would the code be run through and how would I edit and update the code from another computer while itโ€™s running?

boreal ravine
alpine pewter
#

Okay, thank you.[

abstract kindle
#

Iโ€™m trying to find a good spot to learn about self hosting but i canโ€™t really find one

alpine pewter
boreal ravine
unkempt canyonBOT
alpine pewter
#

I thought it had to match, if it was
@bot.run it had to be bot
@client.run it had to be client

#

I'm not even gonna question it, I'm just happy it worked lol

torn sail
#

Just a naming thing

slate swan
#

I was wonderinh how to do i add a number to my command, i want my command to be !10skin

unkempt canyonBOT
#

@discord.ext.commands.command(name=..., cls=..., **attrs)```
A decorator that transforms a function into a [`Command`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command") or if called with [`group()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.group "discord.ext.commands.group"), [`Group`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Group "discord.ext.commands.Group").

By default the `help` attribute is received automatically from the docstring of the function and is cleaned up with the use of `inspect.cleandoc`. If the docstring is `bytes`, then it is decoded into [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") using utf-8 encoding.

All checks added using the [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") & co. decorators are added into the function. There is no way to supply your own checks through this decorator.
torn sail
#

name kwarg

maiden fable
#

Someone ask smth plz lemon_pensive

supple thorn
maiden fable
slate swan
unkempt canyonBOT
#

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

A shortcut method to [`abc.Messageable.send()`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable.send "discord.abc.Messageable.send") to reply to the [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message").

New in version 1.6.

Changed in version 2.0: This function will now raise [`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError "(in Python v3.10)") or [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.10)") instead of `InvalidArgument`.
maiden fable
slate swan
#

im jus playin

astral fossil
#

i need help, there is an error on my bot code:```py
@client.command()
async def open(ctx, arg):
cmd_FileName = str(arg)
if str(ctx.author.id) == '716439189834432523':
varCache_cmd_open0 = open(cmd_FileName, 'r')
varRawReadedDAta = varCache_cmd_open0.read()
varReadedData0 = str(varRawReadedDAta)
varCache_cmd_open0.close()
await ctx.send(varReadedData0)
if str(ctx.author.id) != '716439189834432523':
await ctx.channel.send('Perm level too')

maiden fable
#

Error?

slate swan
#

what is the error..

maiden fable
#

Also why comparing strings? Just compare ints

astral fossil
#

its on the varRawReadedDAta = varCache_cmd_open0.read()

slate swan
#

what does the actual error say?

astral fossil
#

the error read:varRawReadedDAta = varCache_cmd_open0.read()
AttributeError: 'coroutine' object has no attribute 'read'

maiden fable
#

Ah

#

Wait what

#

Ah, change yr command name to smth else

astral fossil
#

ik i never stumbled that error

maiden fable
#

The command function

#

Change its name and use the name kwarg in the decorator and set it to open

astral fossil
astral fossil
#

Changed the name to a10, a11, a12, and a13 still same error

astral fossil
#

what show

maiden fable
#

Code

astral fossil
#

wait

#

Nvm changed the a13 still error

#

Zamn there isalot of unchanged name

#
@client.command()
async def open(ctx, arg):
    a10 = str(arg)
    if str(ctx.author.id) == '716439189834432523':
        a11 = open(a10, 'r')
        a12 = a11.read()
        a13 = str(a12)
        a11.close()
        await ctx.send(a13)
    if str(ctx.author.id) != '716439189834432523':
        await ctx.channel.send('Perm level too')
#

the code

spring flax
#

what are these variable names

astral fossil
spring flax
#

and instead of ```py
async def open(ctx, arg):
a10 = str(arg)

You can directly do 
```py
async def open(ctx, arg : str):
astral fossil
#

Ok

spring flax
#

and...instead of making the ID into a string and comparing with a string why not just use it as itself (an int)
if str(ctx.author.id) == '716439189834432523':
Becomes:
if ctx.author.id == 716439189834432523: