#discord-bots

1 messages · Page 75 of 1

golden tapir
#

how can i fix this error

#
@bot.listen()
async def on_message(message):
  channel = str(message.channel.name)
  user_message = str(message.content)
  guild = message.guild
  id1 = 1012461675624013947
  id2 = 1015374433604616242
  if message.channel.id == id1:
    await bot.get_channel(id2).send(user_message)
outer parcel
#

You would do

#

channel = bot.get_channel(id2)

#

Then await channel.send

#

Separately

#

So altogether

#

channel = bot.get_channel(id2)

#

await channel.send(whatever you want)

sick birch
#

That won't change anything

sick birch
golden tapir
#

what

golden tapir
outer parcel
golden tapir
#

wdym\

#

i want it to take messages from one server and send them to another

golden tapir
#

hm

feral frost
#

like a broadcast command ?

pliant gulch
#

Are you 100% sure your bot has permissions to see the channel from the other server?

outer parcel
golden tapir
#

what are the perms needed

pliant gulch
#

I don't know the exact name off the top of my head, but if you go into that channel in the other server can you see your bot in the member list?

golden tapir
#

ye

outer parcel
#

The bot has perms to view those channels

#

Also the error message does not say missing perms

#

It says the channel is none type

golden tapir
#

what

pliant gulch
#

Which means it wasn't cached

outer parcel
#

Ye

pliant gulch
#

You don't get an error for missing perms with get_channel you get it with fetch channel

golden tapir
#

what does cached mean

outer parcel
#

No it’s says none type has no attribute send

#

Meaning it’s not able to find the channel

golden tapir
#

doe sit have to be the smae channel in both servers?

outer parcel
#

Wdym

pliant gulch
slate swan
#

yo so how can I store the id of a message which i send as this does not work and returns
AttributeError: 'NoneType' object has no attribute 'id'

        message = await interaction.response.send_message(embed=embed, view=view)
        print(message.id)
golden tapir
#

i know what i was doing

#

i am dumb

#

i was getting the server id

#

not the channel id

hushed galleon
slate swan
hushed galleon
#

with await as per docs

slate swan
#

o ye shit

slate swan
# hushed galleon hm ok
        message = await interaction.original_message()

is it like this as it still is returning

AttributeError: 'NoneType' object has no attribute 'id'

hushed galleon
#

can you show the entire traceback?

slate swan
#

sure

slate swan
# hushed galleon can you show the entire traceback?
Ignoring exception in command embed create:
Traceback (most recent call last):
  File "C:\Users\Medwi\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\application_command.py", line 1053, in _call_with_hooks
    await callback(*args)
  File "C:\Users\Medwi\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\application_command.py", line 1135, in call_invoke_slash
    await self.invoke_slash(interaction, **kwargs)
  File "C:\Users\Medwi\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\application_command.py", line 1226, in invoke_slash
    await self.callback(self._self_argument, interaction, **kwargs)
  File "c:\Users\Medwi\OneDrive\Desktop\Coding\modules\Embed\cog.py", line 167, in create
    print(message.id)
AttributeError: 'coroutine' object has no attribute 'id'

The above exception was the direct cause of the following exception:

nextcord.errors.ApplicationInvokeError: Command raised an exception: AttributeError: 'coroutine' object has no attribute 'id'
Ignoring exception in on_application_command_error
Traceback (most recent call last):
  File "C:\Users\Medwi\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\client.py", line 417, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\Medwi\OneDrive\Desktop\Coding\modules\Moderation\cog.py", line 599, in on_application_command_error
    raise error
  File "C:\Users\Medwi\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\application_command.py", line 1053, in _call_with_hooks
    await callback(*args)
  File "C:\Users\Medwi\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\application_command.py", line 1135, in call_invoke_slash
    await self.invoke_slash(interaction, **kwargs)
  File "C:\Users\Medwi\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\application_command.py", line 1226, in invoke_slash
    await self.callback(self._self_argument, interaction, **kwargs)
  File "c:\Users\Medwi\OneDrive\Desktop\Coding\modules\Embed\cog.py", line 167, in create
    print(message.id)
AttributeError: 'coroutine' object has no attribute 'id'
hushed galleon
#

AttributeError: 'coroutine' object has no attribute 'id' is the actual error

#

it means message was a coroutine, and if you unintentionally have one of those, it just needs to be awaited

sick birch
maiden fable
#

yup

#

also u forgot to await the send call

slate swan
feral frost
#

Code:
import discord
from discord.ext import commands

class Buttons(discord.ui.View):
def init(self, *, timeout=180):
super().init(timeout=timeout)
@discord.ui.button(label="Button",style=discord.ButtonStyle.green)
async def gray_button(self,button:discord.ui.Button,interaction:discord.Interaction):
await interaction.response.edit_message(content=f"This is an edited button response!")

@bot.command()
async def button(ctx):
await ctx.send("This message has buttons!",view=Buttons())

Error:
2022-09-04 21:21:33 ERROR discord.ui.view Ignoring exception in view <Buttons timeout=180 children=1> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='Button' emoji=None row=None>
Traceback (most recent call last):
File "C:\Users\Jim\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ui\view.py", line 425, in _scheduled_task
await item.callback(interaction)
File "J:\coding\Vs projects\bot\Merlyn.py", line 2266, in gray_button
await interaction.response.edit_message(content=f"This is an edited button response!")
AttributeError: 'Button' object has no attribute 'response'

How do i solve this ?

unkempt canyonBOT
#

Here's how to format Python code on Discord:

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

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

feral frost
#

?

hollow agate
#

But it should be async def gray_button(self, interaction: discord.Interaction, button: discord.ui.Button):

feral frost
#

ok

#

ill try it

hollow agate
# unkempt canyon

This is how you format code to make it look like code and not like a blob of text

feral frost
#

ok

hollow agate
#
if ctx.channel.id == 69420:
  print('hello')``` for example the colors
hollow agate
#

Whatever tutorial you watched has it wrong

feral frost
#

bruh

#

all that research i did for this thanks man

hollow agate
#

np

feral frost
#

this makes life easier

hollow agate
feral frost
#

btw

#

can i use slash command and text commands in 1 bot ?

toxic hornet
#

i wanted to ask something related to the bot code

feral frost
#

ok

hollow agate
feral frost
#

so much ask in 1 sentence

feral frost
toxic hornet
slate swan
#

How do i get the text of my embed if I store it in a variable?

hollow agate
#

I have something like client = PersistentViewBot() and py @client.command() async def test(ctx): ctx.send('test') and also py @client.tree.command(description="Idk") async def idk(interaction: discord.Interaction): await interaction.response.send_message('idk')

hollow agate
hollow agate
slate swan
#

Okay

toxic hornet
slate swan
#
self.instance = await self.ctx.send(embed=discord.Embed(
            title = f'{self.ctx.author.name}\'s snake game.',
            description = generateSnakeBoard(self.COLUMNS, self.ROWS, self.head, self.body, self.apple)
        ))
#

I store it in self.instance

#

but how do i get the description of that embed

hollow agate
hollow agate
#

Not 100% sure though, just a guess

slate swan
#

doesnt work\

hollow agate
#

Hmmm, not entirely sure then

slow shore
hollow agate
toxic hornet
hollow agate
toxic hornet
#

is ther like a limited prefixes or somethin?

#

sorry because im bad at coding and stuff

hollow agate
#

It's commands.Bot

#

discord.py is not beginner friendly, it's strongly recommended to at least have an understanding of Python before using it.

#

& also you shouldn't be using repl as your host. It's not a host and bots get banned very often. @toxic hornet

toxic hornet
#

so what should i use?

hollow agate
#

An actual host or VPS.

toxic hornet
#

vsc?

hollow agate
#

You could self host it if you want, but just use python3 main.py to run it

toxic hornet
#

got it

hollow agate
#

Hosts are really quite cheap, $1/month for a bot host or maybe $2/month for a VPS that you can do whatever you want with it

toxic hornet
#

i'll do that tomorrow as it's 2 am 😅

#

thx man for helping

hollow agate
#

...just don't get carried away with a lot of hosts 😂

toxic hornet
#

oh lol ok

#

welp i'll be in touch because im dumb so i'll need a lil hand

light jungle
#

How to make it so that such commands were displayed after you clicked on the bot's profile?

hollow agate
#

Is that not just their about me?

wicked atlas
hollow agate
#

ah

light jungle
#

By the way, what is the difference between nextcord and discord.py, since I make bots on both libraries, I didn’t notice the difference

light jungle
wicked atlas
hollow agate
wicked atlas
#

From what I've heard, nextcord is less performant than nextcord

light jungle
wicked atlas
#

damn I didn't catch that one

silk fulcrum
#

shipit noway, is that even possible?

wicked atlas
#

uh

#

¯_(ツ)_/¯

grizzled reef
#

I wanna mimick irl in a discord bot as a project for me to keep learning python

#

Shoukd I make a map for the bot with cities?

lone lichen
slate swan
#

how can i make it so duo points and trio points are next to eachother

#

when i set trio points to inline=True

#

doesnt work

silk fulcrum
hushed galleon
#

you could do it by using an "empty" inline field after solo points, though it would show as a big gap on mobile where inline has no effect

slate swan
#

thats annoying

abstract kindle
#

heyo, for nested Select views, would I have to create a new class for each level?

sick birch
#

How would you nest select views?

#

Do you mean like, multiple select menus per message?

abstract kindle
#

I just mean like once a select option is chosen, a new select menu would appear

sick birch
#

Ah. That's not nested, are you nesting your classes inside of one another?

abstract kindle
#

Should I just have lists of options and swap out which options are in the menu?

#

No, my apologies for bad vocab

sick birch
#

basically, yeah. You'll have to edit the message with a completely new select menu

abstract kindle
#

Would I have to write new classes for that?

sick birch
#

Probably not, though you could

abstract kindle
#

I see. I'll mess around with the options and see what I can come up with

sick birch
#

You can just edit the current select menu and re-send that instead

abstract kindle
#

Sounds good

outer parcel
#

So in trio points field make in-line true

#

I believe that should fix it unless I’m dumb

#

But make duo points in line false

slate swan
vestal dagger
#

takes some to appear for me

final hawk
#

Can someone help me make a discord bot

merry cliff
#

pingme if yo ureply

primal token
slate swan
#

fr

#

yo noid ur smart

#

im using cogs and / commands

final hawk
#

I’ve been trying since last night

final hawk
slate swan
#

how can i have like a listener that sees if someone does something which then gives them something after

#

ive got this rn but it doesnt work

primal token
winged coral
#

You can just call the function yourself as and when

primal token
winged coral
#

You can dispatch an event manually but that's discouraged

primal token
#

By the way listeners are abstracted it lets you register namespaces to you bot e.g setup_hook so not always

winged coral
#

Sure. Doesn't apply here though

final hawk
#

That’s what I was saying can someone help me

#

I’m outside rn tho

primal token
#

API events arent even a thing lol

#

Gateway events are dispatched from the gateway to the client through a bidirectional TCP connection, a websocket

slate swan
#

i appreciate theres a bit of a disagreement here so sorry to but in but what can i do to solve this?

winged coral
#

Well your function is a callback of your own design

#

From the name i'm assuming you're wanting it fired when a user ranks up

slate swan
#

yep

winged coral
#

So, when a user ranks up, call the function yourself

slate swan
#

i understand that part

#

but how can i tell when someone ranks up lmao

winged coral
#

That would depend on your implementation

slate swan
#

like how can i always be waiting/ready for someone to rank up

winged coral
#

What causes someone to rank up?

slate swan
#

so people get points from winning games. these points are saved into a database using sqlite3. to rank up there total number of points across all gamemodes theyve played must pass a certain threshold. for example once they reach 180 points they will recieve the role Bronze 2

winged coral
#

Ok so these games are commands?

#

When they get their points from the games and you add to the database, check if the returned updated value is >= 180

slate swan
#

yes there is a addpoints command that the host of the game gives to someone when they win

winged coral
#

So that's where you check and call the function if need be

slate swan
#

lmao yes i have that

#

but how can i listen for that

#

i dont think im explaining this well

#

what decorator do i need is what im asking

winged coral
#

So in your else clause, call the rank_up function. You don't really need a decorator but if you use command.Listener it gets registered to your bot class as an attr anyway

#

Id just do self.bot.rank_up = self.rank_up in the Cog init

#

Then in the else clause await self.bot.rank_up(...)

slate swan
#

i might have to redesign this

#

because currently i have this ```py
@commands.Cog.listener()
async def rank_up(self, interaction: discord.Interaction, user: discord.Member):
cur.execute(f"SELECT * FROM StrucidDatabase WHERE User = '{user}'")
for row in cur.fetchall():
if row[2] + row[3] + row[4] +[5] >= 90:
if user.has_role(1016072372224270438):
pass
else:
await user.add_roles(discord.Object(id=1016072372224270438)) # Role ID of the role you want to give
await interaction.response.send_message(f"{user.mention} has ranked up to Bronze 3")
elif row[2] + row[3] + row[4] +[5] >= 180:
if user.has_role(1016072383502745701):
pass
else:
await user.add_roles(discord.Object(id=1016072383502745701))
await interaction.response.send_message(f"{user.mention} has ranked up to Bronze 2")
elif row[2] + row[3] + row[4] +[5] >= 270:
if user.has_role(1016072395179708436):
pass
else:
await user.add_roles(discord.Object(id=1016072395179708436))
await interaction.response.send_message(f"{user.mention} has ranked up to Bronze 1")

merry cliff
#

pain

slate swan
#

pain

abstract kindle
#

Heyo, I'm trying to pass final_character here to the command below. How should I do it?

    class CharacterModal(discord.ui.Modal, title="Character Used"):
        character = discord.ui.TextInput(label="Character", placeholder="Waluigi", required=True)

        async def on_submit(self, interaction: discord.Interaction):
            final_character = self.character

Here is the command:

@mk_commands.command(name="upload", description="Upload your fastest time for each course.")
    async def upload(self, interaction: discord.Interaction):

        await interaction.response.send_message("Which **cup** is your course in?", view=MarioKart.CupView())
        character = final_character
merry cliff
# slate swan pain

ok first thing is to make a function that can send message and add role

#

it's just cleaner and you have less copy paste

#

it will cause much less pain later on

#

then I would use discord.utils to get a role instead of calling an object

#

but that's optional

slate swan
#

could u possibly paste this into dms because ngl i’ve been working on this all day and night

#

and it’s killing me

#

gonna get some sleep

merry cliff
#

and next make a calculate level function to return a role and a messsage

#

oksleep is important

slate swan
#

thanks

merry cliff
#

done

slate swan
#

thanks gn

merry cliff
#

np

primal token
abstract kindle
#

For example:

    class CharacterSelector(discord.ui.Select):
        def __init__(self):
            options = []
            super().__init__(placeholder="Choose the character you used", min_values=1, max_values=1, options=options)

        async def callback(self, interaction: discord.Interaction):
            if self.values[0] == "other":
                await interaction.response.send_modal(MarioKart.CharacterModal())
            else:
                character = self.values[0]
            await interaction.response.edit_message(content="What vehicle did you use?", view=MarioKart.VehicleView())
primal token
#

final_character = self.character here its set to the current instance of CharacterModal so you would access its value with the instance created?

abstract kindle
#

The instance is dependent on the user input though. It doesn't always get created. I basically need to have an output from either the Modal or the Select view that I can pass to the command

primal token
#

i cant really help much as im not sure, how its done, why its done or how its abstracted

abstract kindle
#

Basically I have a slash command, and I need to get the output from the different select options that it gives the user. But I don't know how to access those options from the classes they're in.

primal token
#

so each option has its own class with something like a modal i suppose?

abstract kindle
#

So when the command is used, a view gets sent with a bunch of options to pick a course. I want to be able to access that course variable and use it as a variable in the command.

#

Here is the command

@mk_commands.command(name="upload", description="Upload your fastest time for each course.")
    async def upload(self, interaction: discord.Interaction):

        await interaction.response.send_message("Which **cup** is your course in?", view=MarioKart.CourseView())

And here is the select menu that gets sent when the command is used

    class CourseSelector(discord.ui.Select):
        def __init__(self, course_options):
            self.course_options = course_options

            super().__init__(placeholder="Which **course** is the time for?", min_values=1, max_values=1, options=self.course_options)

        async def callback(self, interaction: discord.Interaction):
            course = self.values[0]
primal token
#

And youre trying to access which value?

abstract kindle
#

If I wanted to take the course variable in the bottom line and add it as the next line in the command, how would I do that?

primal token
#

well you can always set it as a instance variable or just use the literal value

upbeat gust
#

here's a basic example of taking a value from the view

primal token
#

Its just instance variables?

upbeat gust
#

yeah

abstract kindle
#

Okay, so if I place the variable in the view, how would I update it from the Select Menu class?

#
    class CourseView(discord.ui.View):
        def __init__(self, options):
            self.options = options
            self.course = None
            super().__init__()


            self.add_item(MarioKart.CourseSelector(options))
#
    class CourseSelector(discord.ui.Select):
        def __init__(self, course_options):
            self.course_options = course_options

            super().__init__(placeholder="Which **course** is the time for?", min_values=1, max_values=1, options=self.course_options)

        async def callback(self, interaction: discord.Interaction):
            course = self.values[0]
upbeat gust
#

youd save your instance of CourseSelector as an instance variable

#

so you can access CourseSelector.value

primal token
#

!e

from dataclasses import dataclass


@dataclass
class Foo:
    bar: str


def monty() -> None:
    foo = Foo("bar")
    return foo.bar

print(monty())
unkempt canyonBOT
#

@primal token :white_check_mark: Your 3.11 eval job has completed with return code 0.

bar
primal token
#

@abstract kindle ^

abstract kindle
#
    class CourseView(discord.ui.View):
        def __init__(self, options):
            self.course = None
            super().__init__()
            view = MarioKart.CourseSelector(options)

            self.add_item(view)

So this instead?

primal token
#

I made it as easiest to understand so it should be understandable to anyone

primal token
abstract kindle
#

Actually, in the example @upbeat gust sent, he handles the outcomes of the view in the command. I've been handling them in the classes of the Select Menus themselves as callbacks

primal token
#

Yeah but the example is quite horrible for its usage, over using something like callbacks but it all depends on abstractions which in the example given its not needed in this case since you want to use a variable thats value is declared inside of the instance you would use instance variables as told

abstract kindle
#

Where do I create the instance?

primal token
#

You declared one and sent it, no?

view=MarioKart.CourseView()
#

you would just use a variable and declare the instance for later references

abstract kindle
#

Let me try something

#

It's getting out of hand. I'm having to track the variable I want over several classes. I send this view after the command is used:

    class CupView(discord.ui.View):
        def __init__(self):
            super().__init__()
            view = MarioKart.CupSelector()
            self.cup = view.cup

            self.add_item(view)

Then, to get THIS classes self.cup I have to have the CupSelector() be sent and then the user will give a response, and then I need to backtrack that response all the way to the command

#
    class CupSelector(discord.ui.Select):
        def __init__(self):
            options = [
                 """options here"""
            ]
            self.cup = None

            super().__init__(placeholder='Choose the cup', min_values=1, max_values=1, options=options)

        async def callback(self, interaction: discord.Interaction):
            self.cup = self.values[0]
``` here is the selector
stone hornet
#

How can I make this work? (The expected result is the bot sending the message that was defined into the function)

def checkUser(message,user2check):
  if user2check.id in registered_users:
    await message.channel.send("Sorry, you are not registered in the database!")

@client.event
async def on_message(msg):
  if msg.content.startswith('?check'):
    checkUser(msg,msg.author)
abstract kindle
#

I would use a command instead of an event for that. It will get hard to track if you run your commands based on message events

abstract kindle
#

Like all your 'commands' would have to be under async def on_message(msg): if you keep doing it that way

stone hornet
#

I got used to making my commands that way

#

And they just work so to me is okay that way

abstract kindle
#

I would avoid that if you want to continue developing

#
@client.command(name="Check")
    async def check(ctx):
      # code here
#

That's a proper command I think. Also I would use bot instead of client

raw gate
#

What's wrong with client? I've been using that for about 2 years now and had no problems

primal token
#

Theres no issue, its just variable naming? Its just not suggested as its not accurate, its like doing

apple = Banana()
slate swan
#
@Arcade.command(name = 'Test', description = 'Testing', guild = discord.Object(id = 1009249121590312980))
async def self(ctx) -> None:
    await ctx.send('hi')
``` Why doesn't a slash command show
quaint scaffold
#

You seem to be using a normal command (text based).

slate swan
#

How can I change it?

slate swan
#

So I have to make a class instance of the bot?

#

Other people said that this method was frowned upon

#

I'll do it.

quaint scaffold
#

Most people subclass it, if that's what you're referring to. Its the most elegant way of adding custom attributes and methods, and allows you to override built-in methods like get_context and setup_hook. If you don't need those features, you could simply use client = discord.Client(...)

slate swan
#

Okay, I'll do it!

#

You are awesome Dan ❤️

cosmic agate
#

how to make so that when ONLY a moderator clicks a button, a response comes?

quaint scaffold
#

❤️

quaint scaffold
quaint scaffold
#

yup

cosmic agate
#

hmm

#

so we can check roles in classes?

quaint scaffold
#

The button callback exposes interaction which is all the data you need

cosmic agate
#

?

#

wait nvm

slate swan
#

@quaint scaffold a guild is my serverId, right?

quaint scaffold
#

?

cosmic agate
#
    def __init__(self, ctx):
        super().__init__(timeout=10)
        self.ctx = ctx
``` this and
```py
    async def interaction_check(self, interaction) -> bool:
      if interaction.user != self.ctx.author:
        await interaction.response.send_message("bro, as the Green Goblin says, To each his own. If you want to have a look, type ?help!", ephemeral= True)
        return False 
      else:
        return True
```right?
quaint scaffold
#

Guilds are just what a normal user calls a server, this prevents confusion between a proper server and a Discord server

slate swan
#

so.... if I right click my server, and click Copy Id, that is it's guild id?

slate swan
#

I'm sorry if im no tunderstanding correctly

cosmic agate
#

thank u

quaint scaffold
#

Fyi that else is redundant

slate swan
#

Okay.

slate swan
#
async def setup_hook(self) -> None:
        self.tree.copy_global_to(guild = 1009249121590312980)
        
        await self.tree.sync(guild = 1009249121590312980)
#

Not sure what is wrong

quaint scaffold
slate swan
#

Fixed it

#

I hope. I did guild = discord.Object(id=id)

slate swan
#

How do I measure the latency

#

If I do a ping command, I wanna measure the ms

vocal snow
#

!d discord.Client.latency

unkempt canyonBOT
#

property latency```
Measures latency between a HEARTBEAT and a HEARTBEAT\_ACK in seconds.

This could be referred to as the Discord WebSocket protocol latency.
cosmic agate
#

hey

#

can we put a view in a view?

vocal snow
#

Sure but what would that achieve

tropic flame
#

hey guys

#

im coding a very basic bot but for some reason it doesnt seem to work

#

import discord
import discord.guild
from discord.ext import commands, tasks

client = commands.Bot(command_prefix='&')

@client.command('reset')
@commands.has_permissions(change_nickname=True)
async def reset(ctx):
for member in ctx.guild.members:
await member.edit(nick=None)

client.run('token')

#

its supposed to change the nickname of everyone in the server to nothing

#

i'll be grateful 4 ur help

paper sluice
#

!or

unkempt canyonBOT
#

When checking if something is equal to one thing or another, you might think that this is possible:

# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
    print("That's a weird favorite fruit to have.")

While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.

So, if you want to check if something is equal to one thing or another, there are two common ways:

# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
    print("That's a weird favorite fruit to have.")

# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
    print("That's a weird favorite fruit to have.")
paper sluice
#

what are you trying to do?

primal token
#

!d random.choice

unkempt canyonBOT
#

random.choice(seq)```
Return a random element from the non-empty sequence *seq*. If *seq* is empty, raises [`IndexError`](https://docs.python.org/3/library/exceptions.html#IndexError "IndexError").
primal token
#

yes?

#

i dont understand why theyre f strings tho, its unnecessary as the string is static

primal token
#

and maybe because youre only checking the start of the string?

worn onyx
#

what is this error?

quick brook
ashen perch
#

Are AppCommandGroup a way to add options to a slash command

hollow agate
slate swan
placid skiff
#

Ohh, ashley made a thing

celest zinc
#

given the user id of someone, how do i get their corresponding member obj?

placid skiff
#

!d discord.Guild.get_member

unkempt canyonBOT
#

get_member(user_id, /)```
Returns a member with the given ID.

Changed in version 2.0: `user_id` parameter is now positional-only.
placid skiff
#

there are other ways too, this is the most common one

celest zinc
#

btw is user id when you do this?

placid skiff
#

this is the id as the bot sees it, but the id is only the integer part of it

celest zinc
#

ah

placid skiff
#

when you mention something the bot will see <@<digits>> or <#<digits>> based if it is a user or a channel/other discord object

ashen perch
#

Thanks!

celest zinc
#

heh?

#

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

#

@placid skiff

winged coral
#

It's guild not bot

#

Read the embed he sent

placid skiff
#

Let's rename this channel into WhenOOPIsOptional

celest zinc
#

?

placid skiff
celest zinc
#

?!!!!!

#

!d discord.Guild.get_member

unkempt canyonBOT
#

get_member(user_id, /)```
Returns a member with the given ID.

Changed in version 2.0: `user_id` parameter is now positional-only.
celest zinc
#

how is this noneType

#

member_obj = server.get_member(690708403504414730)

#

yes ive defined server lol

placid skiff
#

what is server

celest zinc
#
@bot.listen()
async def on_message(payload):
    global server, member, callnresponse, reactionnrole
    channel, server, author, member, message, ID = h.get_msg_info(payload)```
vale wing
#

Wtf

placid skiff
#

bruh D_D

vale wing
#

!d discord.on_message

unkempt canyonBOT
#

discord.on_message(message)```
Called when a [`Message`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Message "discord.Message") is created and sent.

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

Warning

Your bot’s own messages and private messages are sent through this event. This can lead cases of ‘recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that [`Bot`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
celest zinc
#
def get_msg_info(payload):
    return payload.channel, payload.guild, str(payload.author), payload.author, str(payload.content), int(payload.id)
vale wing
#

What kind of "payload" were you expecting

#

It is literal message object

placid skiff
#

Well, now i've saw everything D_D

vale wing
#

No you haven't

#

One sec

#

!e py import base64;[print(chr(int(base64.urlsafe_b64decode(s+"="))>>69),end="") for s in 'NDYwNDMwNzMyMDc5NzkwNDA4MzM1MzY=NTk2MTk4NzY4NDYyMjkyNzA4MjI5MTI=Njk2NTQ5MDU2MjIzMjcyNjY5MDIwMTY=NTk2MTk4NzY4NDYyMjkyNzA4MjI5MTI=NjcyOTM3MjIzODA4OTI0NDQyOTUxNjg=MTg4ODk0NjU5MzE0Nzg1ODA4NTQ3ODQ=NjA4MDA0Njg0NjY5NDY2ODIxMjYzMzY=NjU1MjI4MzQ5NDk4MTYzMjczNDAwMzI=NjQ5MzI1MzkxMzk0NTc2MjE2ODgzMjA=NjQ5MzI1MzkxMzk0NTc2MjE2ODgzMjA=NTcyNTg2OTM2MDQ3OTQ0NDgyMTYwNjQ=MTg4ODk0NjU5MzE0Nzg1ODA4NTQ3ODQ=NjA4MDA0Njg0NjY5NDY2ODIxMjYzMzY=NjE5ODEwNjAwODc2NjQwOTM0Mjk3NjA=Njk2NTQ5MDU2MjIzMjcyNjY5MDIwMTY=NTk2MTk4NzY4NDYyMjkyNzA4MjI5MTI=MTg4ODk0NjU5MzE0Nzg1ODA4NTQ3ODQ=NzE0MjU3OTMwNTM0MDMzODM4NTcxNTI=NjU1MjI4MzQ5NDk4MTYzMjczNDAwMzI=NjkwNjQ2MDk4MTE5Njg1NjEyNTAzMDQ=MTg4ODk0NjU5MzE0Nzg1ODA4NTQ3ODQ=NjkwNjQ2MDk4MTE5Njg1NjEyNTAzMDQ=NjYxMTMxMzA3NjAxNzUwMzI5OTE3NDQ='.split("=") if len(s)>0]

unkempt canyonBOT
#

@vale wing :white_check_mark: Your 3.11 eval job has completed with return code 0.

Never gonna give you up
celest zinc
#

uh

#

dang

placid skiff
#

lmao please bruh the company which i work for sends requests in base64 D_D

maiden fable
#

What the fuck

maiden fable
slate swan
#

Hunter funny af

pulsar solstice
#

How to check a txt file for a message and add that message if not there in asyncio

vocal snow
#

what do you mean in asyncio

slate swan
#

asyncio....?

vocal snow
#

And is this related to discord bots

placid skiff
#

It is not related to discord bots btw as you normally do with a normal file except that you open it asynchronous:
async with open "file.txt": #yourstuff

vocal snow
#

Yeah that won't work

#

You need aiofiles for that

placid skiff
#

well nvm lmao

slate swan
#
import aiofiles

async with aiofiles.open(...) as f:
    await f.read()
#

in an async context ofc

#

and inside an async function*

celest zinc
# placid skiff what is `server`

when i print out type() of the server variable it says<class discord.guild.Guild> but when i print out thetype of the server.get_member([id]) it gives me back <class NoneType>

slate swan
#

get_member is returning None because the method accepts an integer

celest zinc
#

i have the integer

#

member_obj = server.get_member(690708403504414730)

#

it still not working

rugged shadow
#

can we make an async + operator

vocal snow
#

no

#

Well you can make it return a coro

#

But why

warm tulip
#

hhiii

#

HOW I CAN DOWNLOAD DISCORD PY 1.3.7

#

i dont wannna 2.0

#

😐

hazy oxide
#

pip install discord==1.3.7

warm tulip
#

im using replit*

#

it works?

#

in replit?

hazy oxide
#

Use replit shell, but it's temporary

warm tulip
#

what you mean

hazy oxide
#

When u installed modules from replit shell, it will gone after a moment

maiden fable
warm tulip
#

XD

maiden fable
#

That seems about right lol

winged coral
#

🐵

hazy oxide
#

Because you are using replit

winged coral
#

Because replit is awful

hazy oxide
#

Well idk

maiden fable
warm tulip
#

SO SHOULD I CODE IN GITHUB?

winged coral
#

What

warm tulip
#

uh

maiden fable
#

Nvm

warm tulip
#

i hate dpy 2.0

outer parcel
#

basically your bots constantly shut down after a while and come back later

outer parcel
slate swan
vale wing
#

Poetry in vsc is inconvenient imho, it's a lot easier to use in pycharm

outer parcel
#

you can use command prompt and it will also load into vsc your libraries

vale wing
#

Everything stores your libraries in your pc

#

Unless you are using remote coding

outer parcel
#

not replit cause its cloud

vale wing
#

Replit is cringe generally

outer parcel
#

yes

vale frigate
#

Guys py sleep(1) is blocking my code there are any other thing i can use to make same thing that sleep make

rugged shadow
#

that's if you're talking about async apps

vale frigate
#

Oh Yes i use async in my commands

#

Thank You! so how it work asyncio.sleep(1)?

#

Sorry But @rugged shadow

#

soooo sorrrrrrrrrrrrrry

glad cradle
rugged shadow
rugged shadow
vale frigate
#

🙂 ok thank you guys!

#

GUYS WHAT IN THE WORLD???

#

I WAS TRY FIX SOMETHING IN MY CODE FOr 3 DAYS

#

AND I JUST CHANGE FROm sleep to await asyncio.sleep(1) AND IT WORK?

#

WHAT THE HECK lol

#

lol thank you again

slate swan
brazen raft
heavy radish
#

Help. New slash command is confusing

#

I've only got one command

rain olive
heavy radish
#

No. I haven't coded in 5-6 months

heavy radish
#

Wanna get it over with

rain olive
#

in ur Bot instance, u didnt pass in intents

#

pass it in, then good to go

heavy radish
#

What? How?

rain olive
#

@heavy radish

#

whoops

heavy radish
#

What happen?

rain olive
#

you passed "!" as command_prefix

#

right?

#

so pass discord.Intents.all() as intents

heavy radish
#

Thank You

boreal ravine
vale wing
#

Eyes

silk fulcrum
#

👀

boreal ravine
#

What's wrong here?

silk fulcrum
#

if you get an error send it

#

if you do not say what goes wrong

boreal ravine
#

Oops

#

So..

silk fulcrum
#

c from different lang?

boreal ravine
#

Excuse me?

silk fulcrum
#

idk? it says invalid syntax, so your smth is wrong with your async

#

try just rewriting it

quaint scaffold
# boreal ravine

Look at the lines above and below, they may be causing the syntax error

boreal ravine
#

I don't see any pyflakes or anything

silk fulcrum
quaint scaffold
#

The async is fine

#

I'm not sure, maybe check your indentation?

shrewd apex
#

did u save ur code

glad cradle
boreal ravine
boreal ravine
scarlet aurora
#

I'm using sqlite3 to store names in a database, when I call them how can I call just the name, not the [('',)] around the variable

slate swan
#

Are there methods discord.Client.logs_from and discord.Client.delete_messages ?

scarlet aurora
boreal ravine
#

Thanks everyone

quaint scaffold
slate swan
scarlet aurora
slate swan
#
@Client.command(pass_context = True)
async def clear(ctx, number):
    mgs = [] #Empty list to put all the messages in the log
    number = int(number) #Converting the amount of messages to delete to an integer
    async for x in Client.logs_from(ctx.message.channel, limit = number):
        mgs.append(x)
    await Client.delete_messages(mgs)
vocal snow
scarlet aurora
slate swan
#

I'm trying to use it in SlashClient class subinstance from discord.Client:

class SlashClient(discord.Client):
    def __init__(self) -> None:
        super().__init__(command_prefix="/", intents=intents)
        self.tree = discord.app_commands.CommandTree(self)
    
    async def setup_hook(self) -> None:
      self.tree.copy_global_to(guild=discord.Object(id=someInt))
        await self.tree.sync(guild=discord.Object(id=someInt))
scarlet aurora
quaint scaffold
scarlet aurora
#

Ok.

slate swan
quaint scaffold
#

interaction.channel?

slate swan
#

exists ?

quaint scaffold
#

Don't delete messages individually, it counts as one request each time to the API, thus it'll count towards your global ratelimit

boreal ravine
#

How do I fix an ssl error? I get it when I try to start my bot

quaint scaffold
#

That's most likely a poor network connection

scarlet aurora
slate swan
#

@quaint scaffold

#

ah sorry

#

it's channel not chennel

slate swan
#

what discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

#

This is the first time i see this error

#

at await interaction.response.send_message(embed=em)

#

i think because purging the channel messages

#

thanks

slate swan
quaint scaffold
#

!resources You're getting far ahead of yourself making Discord bots if you don't know the basics of Python, I'd heavily recommend learning them first.

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.

heavy radish
#
class abot(discord.Client):
  def __init__(self):
    super().__init__(intents=discord.Intents.default())
    self.synced = False

  async def on_ready(self):
    await tree.sync(guild=discord.Object(id=886817641262637066))
    self.synced = True
    print("Bot is Online")

bot = abot()
tree = app_commands.CommandTree(bot)
# # # # # # # # # # # # # # # # # # # # # # # #

## Quote Command
@tree.command(name="quote", description="quotes an individual", guild = discord.Object(id=886817641262637066))
async def self(interaction: discord.Interaction, Here: str):
  embed = discord.Embed(color = random.choice(colors))
  embed.set_thumbnail(url="https://previews.123rf.com/images/enterline/enterline1612/enterline161200209/66655445-the-word-quotes-concept-and-theme-painted-in-watercolor-ink-on-a-white-paper-.jpg")
  embed.add_field(name="**Quote: **", value=f"{Here}")
  embed.timestamp = datetime.datetime.utcnow()
  embed.set_author(name="Wallahi", icon_url="https://cdn.discordapp.com/icons/683171677185638542/279c659415dab4390087c91f7bc0a753.webp?size=160")
  await interaction.response.send_message(embed=embed)


# # # # # # # # # # # # # # # # # # # # # # # #
bot.run(os.getenv('TOKEN'))
# # # # # # # # # # # # # # # # # # # # # # # #
heavy radish
scarlet aurora
#

How about you just tell me the syntax of index() so I can learn

#

Or send me the docs

slate swan
quaint scaffold
quaint scaffold
heavy radish
scarlet aurora
slate swan
quaint scaffold
#

I'm very confident that you don't index a list using index(); well you could, but its not very practical

scarlet aurora
#

So you're wrong.

cloud dawn
scarlet aurora
#

How is that being rude?

#

He is not helping me, he hasn't even sent the docs I have asked for.

quaint scaffold
#

!resources

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.

scarlet aurora
#

All he is doing is belittling me for not knowing one fucking method.

quaint scaffold
#

Its probably on the first few chapters of whichever guide you choose

cloud dawn
quaint scaffold
scarlet aurora
#

I've never needed it for any projects, that's why I don't know indexing

#

All I wanted is the docs, idk where to find it on that recourses link you sent.

quaint scaffold
#

!e py my_list = list(range(20)) print(my_list[4])

unkempt canyonBOT
#

@quaint scaffold :white_check_mark: Your 3.11 eval job has completed with return code 0.

4
scarlet aurora
#

I know how to do that

cloud dawn
quaint scaffold
#

Doesn't it return a tuple? I haven't used sqlite in ages

heavy radish
#
class abot(discord.Client):
  def __init__(self):
    super().__init__(intents=discord.Intents.default())
    self.synced = False

  async def on_ready(self):
    await tree.sync(guild=discord.Object(id=886817641262637066))
    self.synced = True
    print("Bot is Online")

bot = abot()
tree = app_commands.CommandTree(bot)
# # # # # # # # # # # # # # # # # # # # # # # #

## Quote Command
@tree.command(name="quote", description="quotes an individual", guild = discord.Object(id=886817641262637066))
async def self(interaction: discord.Interaction, Here: str):
  embed = discord.Embed(color = random.choice(colors))
  embed.set_thumbnail(url="https://previews.123rf.com/images/enterline/enterline1612/enterline161200209/66655445-the-word-quotes-concept-and-theme-painted-in-watercolor-ink-on-a-white-paper-.jpg")
  embed.add_field(name="**Quote: **", value=f"{Here}")
  embed.timestamp = datetime.datetime.utcnow()
  embed.set_author(name="Wallahi", icon_url="https://cdn.discordapp.com/icons/683171677185638542/279c659415dab4390087c91f7bc0a753.webp?size=160")
  await interaction.response.send_message(embed=embed)


# # # # # # # # # # # # # # # # # # # # # # # #
bot.run(os.getenv('TOKEN'))
# # # # # # # # # # # # # # # # # # # # # # # #
#

The Error

cloud dawn
outer parcel
scarlet aurora
#

ty

outer parcel
#

change self to quote

#

or smt i think

cloud dawn
#

You haven't provided any info.

#

Any error? Did you debug it? If so where does it get stuck?

heavy radish
outer parcel
#

Oh it says error in here

#

maybe change here to lower case

#

if lower case does not change it maybe change it to text

heavy radish
#

BRO

#

ISTG this is annoying

#

You were right

outer parcel
#

ok

#

changing name does not really affect that much

cloud dawn
#

What join message?

outer parcel
#

Usually i dont have error with this but why cant i access the content of the message

#

this works perfectly in my otherbot

#

all my intents are enabled

cloud dawn
#

The send message?

cloud dawn
outer parcel
#

ye

cloud dawn
outer parcel
#

yep

cloud dawn
#

Afaik you can't delete ephemeral messages.

outer parcel
#

ephemeral are deleted by user

#

when you click dismiss below

#

i dont think you can manually delete those types of messages in code

cloud dawn
#

I don't see a welcome message

#

I see 2 message with welcome system or smth.

outer parcel
#

O are you talking about removing WElcome from aiosqlite table

cloud dawn
#

Well if you are using aiosqlite then you need to commit on execute.

outer parcel
#

type await conn.commit() below it

#

below the execute

outer parcel
#

problem is when i do print(message.content) it returns None

#

therefore meaning intents is not enabled but it is :/

#

is there an error message?

#

so i dont understrand what is not working?

#

is it not deleting it

#

also if i may ask why are you saving a welcome message

#

put commit also beneath saving

#

in aioqsqlite when you are inserting / removing data you have to commit it

#

?

#

why are you using %s

#

wait it might be a different option but idk

#

i use question marsk

#

O your not using aiosqlite?

#

i feel like this is a data base issue and i dont have any experience with aiomysql

#

o

#

wdym

#

like on_message_id

#

edit i mean

vocal snow
#

No

outer parcel
#

no

vocal snow
#

you can use the bot.listen decorator and have as many as you want

#

bot.event decorator will overwrite the bot's internal on_message event. So you can't have multiple of those

cloud dawn
#

That async driver hasn't updated in like what? A good solid 3 years now?

steep estuary
#

how can i get message content intents for my discord bot ?

steep estuary
#

i have to wait till 25 oct ?

honest shoal
#

yes

steep estuary
#

then what about now ?

honest shoal
#

use slash commands

steep estuary
honest shoal
#

yup

steep estuary
#

i used @bot.commands for making all commands

#

my bot has 100 commands

#

ig if i want to migrate to slash commands then i will need to convert all those commands to slash commands ?

#

migrating to slash commands is hard and will take time 😕

slate swan
#

!d discord.Interaction

unkempt canyonBOT
#

class discord.Interaction```
Represents a Discord interaction.

An interaction happens when a user does an action that needs to be notified. Current examples are slash commands and components.

New in version 2.0.
slate swan
#

What does it give me.

#

Guys what does discord.Interaction give me,

honest shoal
unkempt canyonBOT
#

class discord.app_commands.AppCommand```
Represents an application command.

In common parlance this is referred to as a “Slash Command” or a “Context Menu Command”.

New in version 2.0...
honest shoal
silk fulcrum
honest shoal
#

oh yes ^^

slate swan
#

What does discord.Interaction contain?

silk fulcrum
slate swan
steep estuary
silk fulcrum
slate swan
#

Wait nevermind that was dumb.

#

How do I add buttons to an embed?

honest shoal
#

!d discord.ui.button

unkempt canyonBOT
#

@discord.ui.button(*, label=None, custom_id=None, disabled=False, style=<ButtonStyle.secondary: 2>, emoji=None, row=None)```
A decorator that attaches a button to a component.

The function being decorated should have three parameters, `self` representing the [`discord.ui.View`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.ui.View "discord.ui.View"), the [`discord.Interaction`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction "discord.Interaction") you receive and the [`discord.ui.Button`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.ui.Button "discord.ui.Button") being pressed.

Note

Buttons with a URL cannot be created with this function. Consider creating a [`Button`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.ui.Button "discord.ui.Button") manually instead. This is because buttons with a URL do not have a callback associated with them since Discord does not do any processing with it.
steep estuary
slate swan
steep estuary
#

ok

#

is it like this?

@bot.app_command()
or 
@app.command()
honest shoal
#

latter

#

also it's

#

@strange knoll_commands.command()

slate swan
#
# MY class:
class Bot(discord.Client):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        self.tree = app_commands.CommandTree(self)

# Arcade = Bot()
@Arcade.tree.command()
async def apple(interaction: discord.Interaction):
  # Code
silk fulcrum
slate swan
#

:/

#

Damn

#
async def setup_hook(self):
        # This copies the global commands over to your guild.
        self.tree.copy_global_to(guild=MY_GUILD)
        await self.tree.sync(guild=MY_GUILD)
#

Well you will need this part

silk fulcrum
#

yes

cloud dawn
slate swan
#

HEEHEEHAW

steep estuary
slate swan
cloud dawn
#

Client > Bot

steep estuary
cloud dawn
#

Abominations

honest shoal
#

gem_reddisanke is better

slate swan
silk fulcrum
#

perferenece

steep estuary
honest shoal
silk fulcrum
cloud dawn
silk fulcrum
steep estuary
steep estuary
honest shoal
silk fulcrum
#

by the way, doesn't disnake use ctx.respond?

cloud dawn
steep estuary
honest shoal
silk fulcrum
#

but in dpy with hybrid commands u dont have to do that

#

it will just be ctx.send or ctx.reply

steep estuary
#

seriously it will take time to change code of 100+ commands that's why i am asking fastest way to migrate

honest shoal
steep estuary
#

app_commands not found

silk fulcrum
honest shoal
silk fulcrum
#

they just literally change nothing except the name

steep estuary
#

i have to install any module too ?

honest shoal
honest shoal
steep estuary
#

ohhh

#

wait i forgot

#

i forgot that discord.py just released a new update

silk fulcrum
#

"just"

steep estuary
#

:/

silk fulcrum
#

it's already been half a month since a release happened

steep estuary
#

not just ?

silk fulcrum
unkempt canyonBOT
steep estuary
silk fulcrum
#

oh im stupid

#

i thought it was august 18

#

but it is august 28

#

then it's just a week...

slate swan
#

does ```py
bob = interaction.response.send_message('Apple')

not return the message instance?
silk fulcrum
unkempt canyonBOT
#

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

Responds to this interaction by sending a message.
slate swan
#

So it doesnt return anything?

silk fulcrum
#

yep

slate swan
#

Damn it

#

how do I find it then?

silk fulcrum
#

what do you need it for?

slate swan
#

I'm making a snake game on discord, and I am setting their message in a dictionary, so their id = message

silk fulcrum
#

hmmm

slate swan
#

I did it last time with ctx

silk fulcrum
#

im using hybrid commands so ctx.send returns a message object

slate swan
#

idk how to do this thing

#

does it give me ctx?

silk fulcrum
#

idk about app comands one

silk fulcrum
slate swan
#

Damn

silk fulcrum
#

app commands give interaction

slate swan
#

Okay

silk fulcrum
#

however you can make an interaction-based ctx from it

#

i think that can be a solution btw

#

!d discord.ext.commands.Context.from_interaction @slate swan

unkempt canyonBOT
#

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

Creates a context from a [`discord.Interaction`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction "discord.Interaction"). This only works on application command based interactions, such as slash commands or context menus.

On slash command based interactions this creates a synthetic [`Message`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Message "discord.Message") that points to an ephemeral message that the command invoker has executed. This means that [`Context.author`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.author "discord.ext.commands.Context.author") returns the member that invoked the command.

In a message context menu based interaction, the [`Context.message`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.message "discord.ext.commands.Context.message") attribute is the message that the command is being executed on. This means that [`Context.author`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.author "discord.ext.commands.Context.author") returns the author of the message being targetted. To get the member that invoked the command then [`discord.Interaction.user`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction.user "discord.Interaction.user") should be used instead.

New in version 2.0.
honest shoal
#

is there any gist about dpy's localization?

slate swan
#

can you give me an example

silk fulcrum
honest shoal
silk fulcrum
# slate swan can you give me an example
@bot.tree.app_command()
async def my_cool_command(interaction):
    ctx = await commands.Context.from_interaction(interaction)

    my_msg = await ctx.send(...)
    ...```
honest shoal
#

localization in disnake is a bit ugly

silk fulcrum
glad cradle
#

there's examples

honest shoal
glad cradle
silk fulcrum
honest shoal
silk fulcrum
#

!d discord.Locale

unkempt canyonBOT
#

class discord.Locale```
Supported locales by Discord. Mainly used for application command localisation.

New in version 2.0.
honest shoal
#

OH

#

I was at wrong page

slate swan
#

@silk fulcrum do you know abou threading

silk fulcrum
slate swan
#

threading.Thread(target=blah)

#

Does it automatically destroy the thread when its done?

silk fulcrum
#

!d threading

unkempt canyonBOT
#

Source code: Lib/threading.py

This module constructs higher-level threading interfaces on top of the lower level _thread module.

Changed in version 3.7: This module used to be optional, it is now always available.

silk fulcrum
#

interesting

silk fulcrum
slate swan
#

Ah, alright

#

how can i use discord.utils to get a role

silk fulcrum
slate swan
#

because rn im using user.add_roles(discord.Object(id=1016072383502745701))

#

and i was told i should use utils

#

instead of object

silk fulcrum
#

was told by who?

slate swan
#
@Arcade.tree.command()
async def snake(interaction: discord.Interaction) -> None:
TypeError: Interaction client is not derived from commands.Bot or commands.AutoShardedBot

    ctx = await commands.Context.from_interaction(interaction)
    game = games.get(interaction.user.id, None)
    if game is None:
        games[interaction.user.id] = message = await ctx.send('test snake')
    else:
        message = await ctx.send('close')
        threading.Thread(target = deleteMessage, args=(message, 5)).run()

Why isnt this working?

#

someone called unseenyou

silk fulcrum
#

because Object is absolutely possible and I don't see any problem with that

slate swan
#

Okay

#
raceback (most recent call last):
  File "C:\Users\toplo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\tree.py", line 1240, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "C:\Users\toplo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 876, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "C:\Users\toplo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\app_commands\commands.py", line 865, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'snake' raised an exception: TypeError: Interaction client is not derived from commands.Bot or commands.AutoShardedBot
slate swan
#

is it the ctx thing

silk fulcrum
#

but that's optional

slate swan
#

ye ik

#

i was just wondering if its better or not

#

to do that so i was gonna try it

silk fulcrum
#

i dont see any problem with Object

#

and its shorter

slate swan
#

ill stick with it then

silk fulcrum
slate swan
#
ctx = await commands.Context.from_interaction(interaction)

I think its this

slate swan
#

doesnt even work either

silk fulcrum
#

I saw it was a subclass

#

can u send it

slate swan
#

@silk fulcrum ```py
class Bot(discord.Client):
def init(self, *args, **kwargs) -> None:
super().init(*args, **kwargs)

    self.tree = app_commands.CommandTree(self)

async def setup_hook(self) -> None:
    self.tree.copy_global_to(guild = discord.Object(id = 1009249121590312980))
    
    await self.tree.sync(guild = discord.Object(id = 1009249121590312980))
#
Arcade = Bot(intents = discord.Intents.all())
silk fulcrum
#

i guess that is cus it's a Client

#

yes it is

#

only commands.Bot can do from_interaction

steep estuary
#

is this related with hybrid commands

silk fulcrum
#

not discord.Client

slate swan
#

Wait so what do I do?

silk fulcrum
silk fulcrum
steep estuary
#

but this is tricky for me

slate swan
#

Ok lets see now

steep estuary
#

because when i started making my bot i was new to oop

slate swan
#
discord.errors.ClientException: This client already has an associated command tree.
silk fulcrum
slate swan
#
self.tree = app_commands.CommandTree(self)
``` do I remove this part?
slate swan
#
async def setup_hook(self) -> None:
        self.tree.copy_global_to(guild = discord.Object(id = 1009249121590312980))
        
        await self.tree.sync(guild = discord.Object(id = 1009249121590312980))
``` Do i remove these? we didnt define tree unless i inherit it
steep estuary
#

what is this :/

honest shoal
#

!d discord.app_commands.CommandTree

unkempt canyonBOT
#

class discord.app_commands.CommandTree(client, *, fallback_to_global=True)```
Represents a container that holds application command information.
steep estuary
#

is this also new with dc.py 2.0.0 ?

honest shoal
#

yes

slate swan
#

So confused

#

so I don't remove it?

#

Also just making sure, ```py
ctx = await commands.Context.from_interaction(interaction)

#

This is correct?

silk fulcrum
#

yes?

slate swan
#

alr

#

im new to making discord bots, so im sorr.y

#

Okay it works, PROBLEM IS

#
threading.Thread(target = deleteMessage, args=(message, 5)).run()
#

ok wait

silk fulcrum
#

what the heck

#

is that like a task to delete a message after 5 secs?

slate swan
#

yea, if u do time.sleep() it'll pause it for 5 seconds, right?

silk fulcrum
slate swan
silk fulcrum
#

you can

slate swan
#

master

#

@silk fulcrum it doesn't have the attribute, delete_after ```py
await message.delete_after(5)

#

can i pass multiple guild ids here and here

boreal ravine
steep estuary
slate swan
#

OH MY GOD, IM SO DUMB, UR SO SMART, and I wanna eat your poptart

silk fulcrum
steep estuary
hushed galleon
steep estuary
#

i started using discord.py again only for migrating

slate swan
#

It works, now I will be the best programmer in the world. You are all noobs, my plan for world domination is working

steep estuary
#

-_-

boreal ravine
#

You plan to dominate the world.. through a discord bot?

slate swan
slate swan
#

soon the world will be dominated by animated waifus

#

nvm too ambitious

slate swan
#

@slate swan what theme is that

#

async def add(ctx,member : discord.Member,*,reason) -> None :

#

is this code RIGHT ?

buoyant ether
#

Biibebaabelikiikelikaakeli

analog aurora
#

hi is there anyone who knows something abouth python bots and can help me out

sick birch
#

That’s what we’re here for

analog aurora
buoyant ether
#

pip install yaml?

analog aurora
#

idk how

#

can you tell me

#

how pls

buoyant ether
#

open cmd

analog aurora
#

ye

buoyant ether
#

and type pip install yaml

analog aurora
buoyant ether
analog aurora
#

done sir

buoyant ether
#

Try to start the bot now

analog aurora
#

ok thanks

#

it works you are my hero

#

ty

buoyant ether
#

np

analog aurora
#

@buoyant ether can you tell me something more

#

i got more problems

buoyant ether
#

?

analog aurora
#

i mean i download files to bot from web now i dont know why the files dont running with bot

buoyant ether
#

Can you send source?

analog aurora
#

i got this files

#

witch one source

buoyant ether
#

uh wait, so I'm confused rn

#

So, you want to download some files from google and send it with the bot?

#

Like with a command or

analog aurora
#

i mean i want to bot use this files

#

in this files i got casino source

#

i dont know how to get it work

#

i can give you files on pv

#

if u want to

buoyant ether
#

Yea, lets do that

slate swan
#

AttributeError: 'Intents' object has no attribute 'message_content'

fleet ferry
#

how can i join a channel voice channel in which the author of command is in discord.py?

slate swan
#

what to do !

ashen perch
#

quick questions can modals have drop down lists

paper sluice
#

self.callback is a method, why are you trying to subscript it?

atomic glacier
#

Can someone send docs or a video on discord py buttons?

outer parcel
# atomic glacier Can someone send docs or a video on discord py buttons?

This is the Ultimate Python Guide on Buttons with Discord.py or Pycord. In this video, I talk about how to create buttons in discord.py or pycord and how to respond to button clicks along with everything about Views. After watching this you'll know everything about Buttons and Views in discord.py or pycord.

This video might also apply to other...

▶ Play video
hushed galleon
warm ibex
#

AttributeError: module 'discord' has no attribute 'Client'

#

Help

hushed galleon
warm ibex
#

Yes

outer parcel
#

Rename it

hushed galleon
#

^ that script name shadows (i.e. uses the same name as) the discord.py package

outer parcel
#

It’s thinking you want to import that file

scarlet aurora
#

you need 2.0 for buttons

hushed galleon
dull terrace
#

if i wanted to look at a bot that's really well structured and written what open source ones would you recommend

sick birch
dull terrace
#

doge_kek okay

sick birch
#

I haven’t seen any other discord bots that have been laid out and planned that well

#

Very structured

#

Also, extensible and readable

dull terrace
#

that's impossible to google

#

"python discord bot"

sick birch
#

!src

unkempt canyonBOT
sick birch
#

There’s the GitHub

dull terrace
#

thanks

hushed galleon
#

see the example shown in the docs i linked: sql INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b); VALUES would remove your need for that self.callback[0].value parameter you're trying to pass to msg=%s;

#

wdym whats the right one

#

start with how its not working

Ryuga: self.callback is a method, why are you trying to subscript it?
self.callback[0] is incorrect since callback is a method, hence why you got the error 'method' object is not subscriptable

#

you could either fix it by repeating what you wrote for your msg parameter, which is self.children[0].value, or by using mysql's features to avoid repeating the same parameter

steep estuary
#
discord.ext.commands.errors.HybridCommandError: Hybrid command raised an error: Command 'avatar' raised an exception: AttributeError: 'Member' object has no attribute 'avatar_url'

ok this also changed with the new discord.py release ?

slate swan
#

@bot.listen('on_message')
async def on_message(message):
    for line in gg:
        if line in message.content:
            await message.delete()
            await message.channel.send("dont curse")
        break
``` bot not deleting any messages and no error
steep estuary
#

display_avatar is better

maiden fable
#

you need to call self.callback bro

#

Lemme show u what u r doing

#

!e

def func():
    return 1, 2
print(func[0])
unkempt canyonBOT
#

@maiden fable :x: Your 3.11 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 3, in <module>
003 | TypeError: 'function' object is not subscriptable
maiden fable
#

This is what u r trying to do

#

what r u tryna do

steep estuary
#
from discord import app_command
ImportError: cannot import name 'app_command' from 'discord' (/app/.heroku/python/lib/python3.10/site-packages/discord/__init__.py)
#

how to fix this?

placid skiff
steep estuary
sick birch
#

Is that on Heroku or on your local machine?

steep estuary
#

heroku

sick birch
#

Perhaps your project is using a different version than the global, maybe a venv?

steep estuary
#

yes

#

i have discord installed only in my env

analog aurora
#

how to repair it

hushed galleon
vocal snow
hushed galleon
#

also that requirements is weirdly written

steep estuary
#

ok

#

i am seeing it again