#discord-bots

1 messages · Page 964 of 1

formal basin
#

with open('welcome.json') as f: data = json.load(f)

slate swan
#

my apologizes.. my english teacher is dumb.. so is my english :")

#

Return loads(fp.red() ??

quaint epoch
#

@formal basin

cold sonnet
#

the error is coming from the lib's source code?

formal basin
quaint epoch
#

okay now im confused

slate swan
quaint epoch
#

what is going

#

what error is occurring and on what line?

slate swan
slate swan
cold sonnet
# quaint epoch what is going

he used a method of the json lib and the error occured in that code, probably because of an argument passed in wrongly

quaint epoch
#

dude @slate swan , your repos is a one time open. if you open the link and try to open it another tab, it will crash

#

then restart the browser

#

my cpu usage is 100%

cold sonnet
#

the file the error comes from is literally there

#

python libs 3.8 blabla blabla init.py

#

can you host a database on repl

slate swan
#

host?

#

why though

cold sonnet
#

can repl host it for you

slate swan
#

idts

cold sonnet
#

are you tryna say idiots

slate swan
#

precisely

cold sonnet
#

rude

slate swan
#

totally me

cold sonnet
#

well cuz you could get something better than json

quaint epoch
#

doesn't repl provide a free 50 mb db?

slate swan
#

inbuilt

#

within a repl

quaint epoch
#

50 mb isn't a lot, but for a small bot in 2 servers, it's great

cold sonnet
#

in 2 servers like python and dpy

#

sounds horrible

quaint epoch
slate swan
#

I mean, sqlite and postgre still exist

cold sonnet
#

does it on repl tho

quaint epoch
#

idk

slate swan
quaint epoch
#

wait we are discussing db's, right?

#

im not going there, but you can

formal basin
slate swan
quaint epoch
cold sonnet
quaint epoch
#

you pulled a channel_id, not a channel

hushed galleon
quaint epoch
#

try to pull the channel from the guild

cold sonnet
#

economy bots are overrated

formal basin
livid jacinth
#

Hey i try to make a giveaway command but if i try to run the command i get this error discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '<=' not supported between instances of 'set' and 'int'

My Code:

@bot.command(name="giveaway")
@commands.has_permissions(administrator=True)
async def giveaway(ctx, mins : int, *, prize: str):
    user=ctx.author
    end = datetime.datetime.utcnow() + datetime.timedelta(seconds= mins*60)
    embed = discord.Embed( title = "**Giveaway**", description = f"Host: {user}\nPrize: {prize}", color=discord.Color.gold())
    embed.add_field(name= "Ends at:", value=f"{end} (in {mins}min)")

    gwmsg = await ctx.send(embed = embed)
    await gwmsg.add_reaction("🎉")

    await asyncio.sleep(mins)
    gwmsg1 = await ctx.channel.fetch_message(gwmsg.id)
    users = await gwmsg1.reactions[0].users().flatten()
    users.pop(users.index(bot.user))
    winner = random.choice(users)
    await ctx.send(f"{winner.mention} hat {prize} gewonnen!")
quaint epoch
cold sonnet
#

you dare tell me dank memer is an economy bot

quaint epoch
#

try this-

formal basin
cold sonnet
#

no

#

you got the channel_id, use it to get the channel

quaint epoch
cold sonnet
#

just channel

quaint epoch
#

channel = member.guild.get_channel(channel)

livid jacinth
# cold sonnet can we see more of your error?

Traceback (most recent call last):
  File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range```
cold sonnet
#

hu

#

okay but we don't know where this line is cuz you didn't send it

#

it's also a different error 🤔

cold locust
#

if i do

await asyncio.sleep(1)```
how can i edit msg
i tried `await msg.edit("world!")`
got `discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: edit() takes 1 positional argument but 2 were given`
cold sonnet
#

await msg.edit(content="world!")

livid jacinth
cold sonnet
#

maybe it came from
users = await gwmsg1.reactions[0].users().flatten()
?

#

can't be, you fetched the message again

quaint epoch
#

eh

#

why ping

cold sonnet
#

inviting us isn't gonna help

formal basin
quaint epoch
formal basin
cold sonnet
#

the only thing we can do is check your code and we probably are experienced enough to see the problem

cold sonnet
#

with enough information of course

quaint epoch
#

ctrl + z

cold locust
#

worked

cold sonnet
formal basin
quaint epoch
#

channel_id, is an id, so the int from the json file

#

you just have to fetch a channel from it

cold sonnet
#
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range
```this is not a whole traceback
quaint epoch
cold sonnet
#

and includes many stuff except the line in your code

formal basin
quaint epoch
formal basin
cold sonnet
quaint epoch
#
channel = data[str(member.guild.id)]["channel_id"]
channel = member.guild.get_channel(channel)```
quaint epoch
quaint epoch
formal basin
#

Oh

cold sonnet
#

@formal basin channel = bot.get_channel(data[str(member.guild.id)]['channel_id'])

livid jacinth
quaint epoch
#

but sure

#

anyway gtg

cold sonnet
#

"The above exception"
means the exception above that line

#

because there is an exception

livid jacinth
#

oh my bad ```Ignoring exception in command giveaway:
Traceback (most recent call last):
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\tim10\OneDrive\Desktop\Testbebo\bot - Kopie.py", line 84, in giveaway
await asyncio.sleep({mins})
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\asyncio\tasks.py", line 638, in sleep
if delay <= 0:
TypeError: '<=' not supported between instances of 'set' and 'int'

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

Traceback (most recent call last):
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '<=' not supported between instances of 'set' and 'int'
Ignoring exception in command giveaway:
Traceback (most recent call last):
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
await asyncio.sleep({mins})```

cold sonnet
#

thanks, that's help

livid jacinth
# livid jacinth > oh my bad ```Ignoring exception in command giveaway: > Traceback (most recent ...
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\asyncio\tasks.py", line 638, in sleep
  if delay <= 0:
TypeError: '<=' not supported between instances of 'set' and 'int'

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

Traceback (most recent call last):
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
  await ctx.command.invoke(ctx)
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
  await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\tim10\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
  raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '<=' not supported between instances of 'set' and 'int'```
cold sonnet
#

now wait that's a problem in the asyncio lib

#

not sure why there's {} around mins

#

oh it's actually in discord's source code

slate swan
#

wow

#

ah nvm

cold sonnet
#

they did mess up bro

#

lemme look on github

unkempt canyonBOT
#

discord/ext/commands/core.py line 85

'dm_only',```
cold sonnet
#

oh got it

#

File "c:\Users\tim10\OneDrive\Desktop\Testbebo\bot - Kopie.py", line 84, in giveaway
await asyncio.sleep({mins})

#

remove {} around mins

cold sonnet
#

those {}

neon spear
#

Hi guys, I'm using this code for a while. However last week for some reason it stopped working and only giving me one message instead of the 20 limit I gave the bot. Any idea on this, is there a new update?


    channel = bot.get_channel(962066339386777690)    # get channel ID
    async for message in channel.history(limit=20):  # read last 20 messages from channel
        print(message.attachments[0].url)            # print out 20 messages

cold sonnet
#

message intents

#

oh but it does read 1 message

neon spear
#

Yes it does read 1 message instead the 20 i gave him :S

cold sonnet
#

did u change something

#

something else

neon spear
#

Nope, haven't changed anything for like 1 year

cold sonnet
#

are there more stuff in that for loop

neon spear
#

Here the whole function for a better understanding


@bot.command()
async def updb(ctx):
    collection.drop()
    time.sleep(1)
    channel = bot.get_channel(962066339386777690)
    async for message in channel.history(limit=20):
        print(message.attachments[0].url)
        urlArray.append(url)

    for url in urlArray:
        print(url)
        collection.insert_one({"url": url}
left crater
#

they changed it in 2.0

#

you have to use list comps now

#

messages = [messages async for messages in channel.history(limit=None)]looks something like this

neon spear
#

Oof, okay will check this out

left crater
#

time.sleep is blocking

neon spear
dull terrace
#

what would be the best method for checking for dates connected to an image and deleting older ones? I'm thinking a very slow loop to spread out the cpu usage that checks each image because it's not time sensitive.

hushed galleon
hushed galleon
#

as for the print not working, if you didnt tweak the limit=None in their example your bot would fetch every message in the channel, possibly hitting ratelimits

neon spear
#

I do not have an on_command_error event and that's why i'm using limit=20

brisk plover
#

Hey, so if i have a message.content and im using .startswith("OE")
I want to find if it starts with OE or oe, regardless of uppercare or lowercase.

neon spear
#

It's weird because i haven't changed the code for like a year or even longer

hushed galleon
#

hm did you update discord.py recently or is it still on a stable version

neon spear
#

Didn't update anything

hushed galleon
#

oh and is it guaranteed that every message in your channel will have at least one attachment?

junior verge
#
@commands.Cog.listener()
    async def on_message(self, message):
    
            channel = self.client.get_channel(962081173545287691)
            embed = Embed(
                description=f"Message sent in {message.channel.mention}", color=0x4040EC
            ).set_author(name=message.author, url=Embed.Empty, icon_url=message.author.avatar_url)

            embed.add_field(name="Message", value=message.content)
            embed.add_field(name="User ID:", value=message.author.id, inline=False)
            embed.timestamp = message.created_at
            await channel.send(embed=embed)
``` This is just for testing but how do I add that images also show in here as it gives me this error
hushed galleon
neon spear
honest shoal
#

!d discord.Embed.set_image

unkempt canyonBOT
#

set_image(*, url)```
Sets the image for the embed content.

This function returns the class instance to allow for fluent-style chaining.
junior verge
#

it works tho

sick birch
honest shoal
#

oh

sick birch
#

Anything

#

The important part is the or

#

Other stuff can be whatever, isn't that important

junior verge
#

Do you get me just wondering

sick birch
#

The problem arises that just because a message doesn't have message.content doesn't mean it's an image

#

For example it could be a message like so:

junior verge
#

Oh

sick birch
#

_ _

#

That would also throw an error when deleted

junior verge
sick birch
#

Yes it needs to be message.content or "No message content"

#

!e

x = None
print(x or "x was none")
unkempt canyonBOT
#

@sick birch :white_check_mark: Your eval job has completed with return code 0.

x was none
junior verge
#

Can I also make it so images show up there

sick birch
#

You would need an additional check

junior verge
#

How?

sick birch
#

To see if the message had any attachments

#
if message.attachments:
  # message has attachments
else:
  # message was just an empty message
junior verge
#

Like if message.attachments then embed.add field?

#

not really sure on how to do that

#
@commands.Cog.listener()
    async def on_message_delete(self, message):
    
            channel = self.client.get_channel(954837357239091260)
            deleted = Embed(
                description=f"Message deleted in {message.channel.mention}", color=0x4040EC
            ).set_author(name=message.author, url=Embed.Empty, icon_url=message.author.avatar_url)

            if message.attachments:
                deleted.add_field()
            else:
                deleted.add_field(name="Message:", value=(message.content or "No message content"))
                deleted.timestamp = message.created_at
            await channel.send(embed=deleted)
``` something like that
#

Then add something if its a image

hushed galleon
junior verge
#

Just want the image to show thats it

hushed galleon
#

you cant show an image in your embed if you dont know where images can be shown in your embed

junior verge
#

Oh yeah I get where they are shown

hushed galleon
#

but you wrote add_field() which is related to these things

junior verge
#

I know

hushed galleon
junior verge
#

Just don't know what to put in it yet

#
@commands.Cog.listener()
    async def on_message_delete(self, message):
    
            channel = self.client.get_channel(954837357239091260)
            deleted = Embed(
                description=f"Message deleted in {message.channel.mention}", color=0x4040EC
            ).set_author(name=message.author, url=Embed.Empty, icon_url=message.author.avatar_url)

            if message.attachments:
                deleted.set_image(*, url)
            else:
                deleted.add_field(name="Message:", value=(message.content or "No message content"))
                deleted.timestamp = message.created_at
            await channel.send(embed=deleted)
``` how do I do that with the (*, url)
hushed galleon
#

in documentation and when defining your own functions, writing a * means any parameters after it are keyword-only

junior verge
#

So what should I set the parameters to?

hushed galleon
#
def download(*, url):
    ...  # the magic of the internet

>>> download(url='https://link.to.my.favourite.image.png')```
#

in your case the url you want is the attachment's url

junior verge
#

Sorry I got no clue on how to do this in my case

hushed galleon
#

!d discord.Attachment.url

unkempt canyonBOT
#

The attachment URL. If the message this attachment was attached to is deleted, then this will 404.

hushed galleon
#

and you can get a list of attachments from message.attachments

junior verge
#

Hm?

#
(self, message, attachment):
``` do i do that?
hushed galleon
#

no, your message object already has the attachments within it

#

!d discord.Message.attachments

unkempt canyonBOT
junior verge
#
@commands.Cog.listener()
    async def on_message_delete(self, message):
    
            channel = self.client.get_channel(954837357239091260)
            deleted = Embed(
                description=f"Message deleted in {message.channel.mention}", color=0x4040EC
            ).set_author(name=message.author, url=Embed.Empty, icon_url=message.author.avatar_url)

            if message.attachments:
                deleted.set_image(message.attachment.url)
            else:
                deleted.add_field(name="Message:", value=(message.content or "No message content"))
                deleted.timestamp = message.created_at
            await channel.send(embed=deleted)
``` how would that be?
hushed galleon
#

the attribute is attachments, plural, and you need to index the first attachment from it like you would with a regular list

#

!e py fruits = ['apple', 'orange', 'banana'] print('The second fruit is', fruits[1])

unkempt canyonBOT
#

@hushed galleon :white_check_mark: Your eval job has completed with return code 0.

The second fruit is orange
slate swan
#

@bot.slash_command(guild_ids=[TESTING_GUILD_ID], description="Repeats your message")
async def echo(interaction: Interaction, arg: nextcord.Message = SlashOption(description="Message")):
    await interaction.response.send_message(arg)```
junior verge
#

But how do I do that with my attachments? hm?

slate swan
junior verge
hushed galleon
#

what you need to ask yourself is how do you get the first item from a list in general, and knowing the answer to that question will naturally let you figure out how to index the first item from a message's list of attachments

junior verge
#

I just don't get it

#

Just if someone delets a message, IF it has a image then show the image as well thats just it

hushed galleon
#

well there's a caveat to that which means a different solution is needed, but its worth knowing that the solution i suggested you is based on the most essential knowledge, so its really important you learn instance attributes and lists

junior verge
#

I know them.... I just don't get what you are trying to tell

hushed galleon
#

anyway after a message is deleted, any of its attachments are eventually deleted from discord, so you need to download it and reupload it as an attachment in your log

junior verge
#

oh okay

hushed galleon
#

after you get the first attachment from the message you can download it using the to_file() method with the use_cached=True argument (which works better for recently deleted messages), then embed it using set_image() following this <#discord-bots message>

#

as for the filename you can get it with the .filename attribute of your File object

#

!d discord.File.filename

unkempt canyonBOT
#

property filename```
The filename to display when uploading to Discord. If this is not given then it defaults to `fp.name` or if `fp` is a string then the `filename` will default to the string given.
junior verge
#

I don't need it like that, but thanks

#
@commands.command(name="lock", description="Locks a channel so users can't speak it in")
    @commands.has_permissions(manage_channels=True)
    async def lock(self, ctx, channel: discord.TextChannel=None):
        channel = channel or ctx.channel

        if ctx.guild.default_role not in channel.overwrites:
            overwrites = {
                ctx.guild.default_role: discord.PermissionOverwrite(send_messages=False)
            }
            await channel.edit(overwrites=overwrites)
            await ctx.send(f"I have put `{channel.name}` on lockdown")
        elif channel.overwrites[ctx.guild.default_role].send_messages == True or channel.overwrites[ctx.guild.default_role].send_messages == None:
            overwrites = channel.overwrites[ctx.guild.default_role]
            overwrites.send_messages = False
            await channel.set_permissions(ctx.guild.default_role, overwrite=overwrites)
            await ctx.send(f"I have put `{channel.name}` on lockdown")
``` Why does this say command not found? It used to work.
slate swan
junior verge
slate swan
#

what should i add to my bot im bored and i want to add someting fun to my bot

junior verge
slate swan
junior verge
#

Just lock doesn't seem to work it's really weird

junior verge
torn sail
#

Do u have any other methods in the cog named lock?

junior verge
#

unlock

torn sail
#

The exact same name?

slate swan
junior verge
#

Nope just unlock

slate swan
#

Idk tbh💀😭

junior verge
#

Here look

slate swan
#

It should be working doe

junior verge
#

Yeah it used to work like 20m ago lmao

#
@commands.command(name="lock", description="Locks a channel so users can't speak it in")
    @commands.has_permissions(manage_channels=True)
    async def lock(self, ctx, channel: discord.TextChannel=None):
        channel = channel or ctx.channel

        if ctx.guild.default_role not in channel.overwrites:
            overwrites = {
                ctx.guild.default_role: discord.PermissionOverwrite(send_messages=False)
            }
            await channel.edit(overwrites=overwrites)
            await ctx.send(f"I have put `{channel.name}` on lockdown")
        elif channel.overwrites[ctx.guild.default_role].send_messages == True or channel.overwrites[ctx.guild.default_role].send_messages == None:
            overwrites = channel.overwrites[ctx.guild.default_role]
            overwrites.send_messages = False
            await channel.set_permissions(ctx.guild.default_role, overwrite=overwrites)
            await ctx.send(f"I have put `{channel.name}` on lockdown")

    @commands.command(name="unlock", description="Unlocks a channel so users can speak in it")
    @commands.has_permissions(manage_channels=True)
    async def lock(self, ctx, channel: discord.TextChannel=None):
        channel = channel or ctx.channel

        if ctx.guild.default_role not in channel.overwrites:
            overwrites = {
                ctx.guild.default_role: discord.PermissionOverwrite(send_messages=True)
            }
            await channel.edit(overwrites=overwrites)
            await ctx.send(f"I have unlocked `{channel.name}` for you")
        elif channel.overwrites[ctx.guild.default_role].send_messages == True or channel.overwrites[ctx.guild.default_role].send_messages == None:
            overwrites = channel.overwrites[ctx.guild.default_role]
            overwrites.send_messages = False
            await channel.set_permissions(ctx.guild.default_role, overwrite=overwrites)
            await ctx.send(f"I have unlocked `{channel.name}` for you")
slate swan
#

Just make sure that ur cog is loaded

junior verge
#

oh fuck lmfaoo

#

sorry for wasting your guys time lmao

torn sail
#

All good

slate swan
torn sail
#

Happened to me before

slate swan
slate swan
junior verge
slate swan
#

Can we see the whole code?

junior verge
#

Prints xD

junior verge
slate swan
#

Yes

junior verge
#
@commands.command(name="lock", description="Locks a channel so users can't speak it in")
    @commands.has_permissions(manage_channels=True)
    async def lock(self, ctx, channel: discord.TextChannel=None):
        channel = channel or ctx.channel

        if ctx.guild.default_role not in channel.overwrites:
            overwrites = {
                ctx.guild.default_role: discord.PermissionOverwrite(send_messages=False)
            }
            await channel.edit(overwrites=overwrites)
            await ctx.send(f"I have put `{channel.name}` on lockdown")
        elif channel.overwrites[ctx.guild.default_role].send_messages == True or channel.overwrites[ctx.guild.default_role].send_messages == None:
            overwrites = channel.overwrites[ctx.guild.default_role]
            overwrites.send_messages = False
            await channel.set_permissions(ctx.guild.default_role, overwrite=overwrites)
            await ctx.send(f"I have put `{channel.name}` on lockdown")

    @commands.command(name="unlock", description="Unlocks a channel so users can speak in it")
    @commands.has_permissions(manage_channels=True)
    async def unlock(self, ctx, channel: discord.TextChannel=None):
        channel = channel or ctx.channel

        if ctx.guild.default_role not in channel.overwrites:
            overwrites = {
                ctx.guild.default_role: discord.PermissionOverwrite(send_messages=True)
            }
            await channel.edit(overwrites=overwrites)
            await ctx.send(f"I have unlocked `{channel.name}` for you")
        elif channel.overwrites[ctx.guild.default_role].send_messages == True or channel.overwrites[ctx.guild.default_role].send_messages == None:
            overwrites = channel.overwrites[ctx.guild.default_role]
            overwrites.send_messages = True
            await channel.set_permissions(ctx.guild.default_role, overwrite=overwrites)
            await ctx.send(f"I have unlocked `{channel.name}` for you")
slate swan
#

But i think the issue is in the name and the async def since name and async def have the same name

#

Idk try to change the names?

junior verge
#

I have that for like all my commands

slate swan
slate swan
junior verge
#

Cog is loaded.

junior verge
slate swan
junior verge
#

Nothing lol

slate swan
#

Can u !paste cuz im on phone i cant see ur code clearly

junior verge
#

kk

slate swan
#

Alr

junior verge
#

!paste

slate swan
#

Oh well its bc u put the code inside if and elif statnts

#

Statements***

#

Also the default role always in the channel overwrites so no need to add that

junior verge
#
@commands.command(name="unlock", description="Unlocks a channel so users can speak in it")
    @commands.has_permissions(manage_channels=True)
    async def unlock(self, ctx, channel: discord.TextChannel=None):
        channel = channel or ctx.channel
        overwrites = {ctx.guild.default_role: discord.PermissionOverwrite(send_messages=True)}
        await channel.edit(overwrites=overwrites)
        await ctx.send(f"I have unlocked `{channel.name}` for you")
``` so just like this
slate swan
lucid vine
#
class Dropdown(discord.ui.Select):
    def __init__(self):
        # Set the options that will be presented inside the dropdown
        options = [
            discord.SelectOption(label='Menu', description='Help Menu', emoji='📖'),
            discord.SelectOption(label='NSFW', description='NSFW commands', emoji='🔞'),
            discord.SelectOption(label='Fun', description='Fun commands', emoji='😊'),
            discord.SelectOption(label='Mod', description='Moderation commands', emoji='🔧'),
        ]

        # The placeholder is what will be shown when no option is chosen
        # The min and max values indicate we can only pick one of the three options
        # The options parameter defines the dropdown options. We defined this above
        super().__init__(placeholder='Pick your Category...', min_values=1, max_values=1, options=options)

    async def callback(self, interaction: discord.Interaction):
        # Use the interaction object to send a response message containing
        # the user's favourite colour or choice. The self object refers to the
        # Select object, and the values attribute gets a list of the user's
        # selected options. We only want the first one.
        if self.values[0] == 'NSFW':
            buttonforward = Button(emoji="➡️", style=discord.ButtonStyle.gray)
            async def button_callback(interaction):
                await interaction.response.edit_message(embed=embednsfw2)
            buttonforward.callback = button_callback
            buttonback = Button(emoji="⬅️", style=discord.ButtonStyle.gray)
            async def button_callback(interaction):
                await interaction.response.edit_message(embed=embednsfw)
            buttonback.callback = button_callback
            for item in self.view.children:
                self.view.add_item(buttonback)
                self.view.add_item(buttonforward)
            await interaction.response.edit_message(embed=embednsfw, view=self.view)
        elif self.values[0] == 'Mod':
           await interaction.response.edit_message(embed=embedmod)
        elif self.values[0] == 'Fun':
           await interaction.response.edit_message(embed=embedfun)
        elif self.values[0] == 'Menu':
           await interaction.response.edit_message(embed=embedhelp)

can someone help me iterating through my views children because else idk how ima get the items in my views

#

Average discord users have died

hoary cargo
#

just use a regular embed if you gonna use buttons

lucid vine
#

I want to use like dropdowns for categories

#

And buttons to like direct pages

hoary cargo
#

i mean, when a user pics a category you can just display him an embed with the commands in that category, i don't see why would you need buttons, tbh it's a pretty twisted thing

lucid vine
#

Thats why i wanted to add pages

#

And navigate with the buttons

hoary cargo
#

ciudat really long like? it does have more than 20-30 commands?

lucid vine
#

Yes

#

If i display it in 1 embed

#

Its like spam

#

horny bot

hoary cargo
#

well, a solution would be to add another option for Part 2 of nsfw, i don't know how well works buttons with dropdowns together

lucid vine
sick birch
#

Let's adhere to the channel topic and not shitpost, please

lucid vine
sick birch
#

It does not appear so, no

lucid vine
#

Do you ride sticks

lucid vine
#

Who initiated the cmd

full lily
sick birch
lucid vine
lucid vine
boreal ravine
#

Chill out

sick birch
#

Let's just refrain from doing that in the future, thanks 🙂

#

Now, back to the problem at hand

hoary cargo
#

ciudat damn i left for a bit and people already arguing

hoary cargo
slate swan
#

what the heck happened here

haughty quartz
#

how do they use a different one-line code

#

in a embed

sick birch
#

Timestamps?

slate swan
unkempt canyonBOT
#

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

001 | hello
002 | world!
slate swan
#

this?

#

im not sure what you mean tbh

sick birch
#

Me neither

final iron
#

Hello okimii 🗿

haughty quartz
#

nah, one is darker than the other

final iron
#

Oh you mean this?

haughty quartz
#

yes

sick birch
#

Because the first one is a timestamp, the 2nd line is a single line code block

haughty quartz
#

interesting

sick birch
#

Quite

haughty quartz
#

how does that work though? how do i create such a timestamp

slate swan
#

`hello world`

#

like that

sick birch
slate swan
slate swan
haughty quartz
haughty quartz
sick birch
#

You need the UNIX timestamp

#

In seconds

slate swan
haughty quartz
#

alright, thanks a lot @slate swan @sick birch !

pliant gulch
#

!d discord.utils.format_dt

unkempt canyonBOT
#

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

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

Does anyone know how can I host a bot for free?

slate swan
#

Replit.

#

Quick answer

final iron
twilit tusk
#

Replit does not have all time hosting

#

I need to be on as long as I can

final iron
#

You don't need anything powerful

#

Oracle free tier is also an option

slate swan
# final iron No.

Literally the only choice im guessing they dont have a cc so they cant try free trials from big companies like google or they dont have an laptop sitting around i dont see other options

slate swan
final iron
slate swan
final iron
#

Not really

slate swan
#

Mhmm

final iron
#

Replit is a terrible option though

twilit tusk
#

I don't have a cc though. So idk

#

Thanks for the help tho <3

final iron
#

If you have a bit of cash you could probably buy a prepaid cc from a gas station

#

Then buy a cheap host

twilit tusk
#

I tried... But in here I couldn't find anything

#

I live in argentina :/

slate swan
#

Also the phone number is probably linked to that person

final iron
#

Asking friends for an old laptop is an option. You don't need anything really powerful for hosting

slate swan
twilit tusk
#

I do have a debit card... But tbh I don't feel like paying 15 usd a month for a host for a single bot

final iron
#

There are cheaper options in the pins

slate swan
#

so im having a problem with this reactrole code is

#
@commands.Cog.listener()
    async def on_raw_reaction_add(self, payload):
        messageID=961835417320161310

        if messageID== payload.message_id:
            member=payload.member
            guild=member.guild

            emoji= payload.emoji.name
            if emoji==":black_drip:":
                role=discord.utils.get(guild.roles, name="evnt")
            if emoji==":BlackFire:":
                role=discord.utils.get(guild.roles, name="gw")
            await member.add_roles(role)```
#

i get an error of: UnboundLocalError: local variable 'role' referenced before assignment

#

i think it has to do with something around the "await member.add_roles(role) part idk

#

but does anyone know how to fix this issue? thx

slate swan
unkempt canyonBOT
#

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

001 | Traceback (most recent call last):
002 |   File "<string>", line 4, in <module>
003 |   File "<string>", line 2, in a
004 | UnboundLocalError: local variable 'b' referenced before assignment
potent helm
slate swan
#

thats not his point

#

hes saying role would be undefined if both of those conditions are False

potent helm
#

Minimal alteration to existing code

slate swan
#

that exact same thing

#

then you must had something wrong.

potent helm
#

Is there a different error message with the code I sent?

pliant gulch
#

You should verify that emoji.name is either :black_drip: or :BlackFire: EXACTLY since those seem to be custom emojis?

#

You should print payload.emoji.name for each reaction and see what exactly you should be doing

#

:black_drip: etc to me seem wrong

potent helm
stuck oyster
#
line 93, in button_callback2
    await interaction.response.defer.send_message(f"Your ticket has been created, go to {channel.mention}", ephemeral=True)
AttributeError: 'function' object has no attribute 'send_message'```
stuck oyster
stuck oyster
final iron
#

Like not all, all

#

Just the function

stuck oyster
#

its a class

#
await interaction.response.defer.send_message(f"Your ticket has been created, go to {channel.mention}", ephemeral=True)```
#

what of this? because that is where the problem is

torn sail
#

Well you can send a message or defer

stuck oyster
torn sail
#

!d discord.InteractionResponse.defer

unkempt canyonBOT
#

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

Defers the interaction response.

This is typically used when the interaction is acknowledged and a secondary action will be done later.

This is only supported with the following interaction types...
flat solstice
#

is there a way for me to manually spawn more shards for a AutoShardedBot

torn sail
#

!d discord.InteractionResponse.send_message

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.
stuck oyster
#

oh

#

so if I use defer it would send

torn sail
#

You are doing interaction.defer.send_message

sonic patio
#

how to get emoji from name

torn sail
#

No defer sends the “thinking”

torn sail
stuck oyster
torn sail
#

That wouldn’t send a message

#

So what r u trying to do

stuck oyster
#

sends the message

#

it works

#

its just that it times out if it doesnt respond in 3secs

torn sail
#

Ohhhh

#

Then use defer and then use interaction.followup.send to respond

stuck oyster
#

what do you mean?

torn sail
#

So to indicate that u may take over 3 seconds u use interaction.response.defer(…)

flat solstice
torn sail
#

Then interaction.followup.send(…) to respond with messages

#

!d discord.InteractionResponse.defer

unkempt canyonBOT
#

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

Defers the interaction response.

This is typically used when the interaction is acknowledged and a secondary action will be done later.

This is only supported with the following interaction types...
quaint epoch
#

okay yeah that works

stuck oyster
#
        await interaction.response.defer()
        await interaction.followup.send(f"Your ticket has been created, go to {channel.mention}", ephemeral=True)```
patent hemlock
patent hemlock
torn sail
#

Yeah

#

Not sure if ephemeral works with that tho

patent hemlock
boreal ravine
#

yes?

patent hemlock
#

oh

#

maybe I should use discord.js

boreal ravine
#

go for it

patent hemlock
boreal ravine
torn sail
#

I don’t think interaction.py supports message based commands. I’ve heard hikari gives more control to the user and is more advanced

patent hemlock
#

Idk much about it, but I just heard hikari is better from some ppl

slate swan
#

it honestly depends on skill and preference

patent hemlock
slate swan
torn sail
patent hemlock
#

preference of what

slate swan
#

to me i like disnake because of its impl

patent hemlock
#

ok

quaint epoch
#

hear me out: amogus

#

jk, but just a question

#

difference between discord.Client and discord.ext.commands.Bot

#

and could i use discord.Client to make new discord client(i know against tos, but im not)

#

idk how to do it anyway

boreal ravine
#

Bot = a subclass of Client, has support for text commands
Client = has support for discord stuff only

quaint epoch
#

so technically, it would be possible to make a client with .Bot?

#

if you can make a client with .Client

boreal ravine
#

wait what client?

slate swan
#

The Client class is the super class of the Bot class yes

hybrid ravine
#

is there a way to get all the messages in a chabnnel?

tough lance
quaint epoch
boreal ravine
slate swan
unkempt canyonBOT
#

async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)```
Returns an [asynchronous iterator](https://docs.python.org/3/glossary.html#term-asynchronous-iterator "(in Python v3.10)") that enables receiving the destination’s message history.

You must have [`read_message_history`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.read_message_history "discord.Permissions.read_message_history") permissions to use this.

Examples

Usage...
quaint epoch
#

just limit=None to loop through all messages

hybrid ravine
#

ty 🙂

pulsar thunder
#

I have a question again I used

If they in message.content:
do some stuff

Thing is it's also detecting hey in the word they sooo.... how to fix it?

sick birch
#

Oh never mind misread that

hybrid ravine
#

is there a waqy to gather all the channels in a server (as names)with all the messages?

pulsar thunder
#

Name to appear with message in output log?@hybrid ravine

hybrid ravine
pulsar thunder
#

Not familiar with xenon sorry

hybrid ravine
pulsar thunder
#

In my code I got it to recognize every message in the server and print the message along with the guy who sent it and channel name

#

The code on first pic with some closing statements later like return and such@hybrid ravine

hybrid ravine
#

lemme take a look

pulsar thunder
#

Sad thing it was not even the purpose of the bot

#

Also any commands with the word list just ignore them

supple thorn
hybrid ravine
#

can someone help?

<discord.iterators.HistoryIterator object at 0x000001E03DBD0790>

im tryna get it to come up with the history of the channel i message in and this is the return i get

heavy folio
slate swan
slate swan
sick birch
hybrid ravine
slate swan
fossil aspen
slate swan
unkempt canyonBOT
hybrid ravine
pulsar thunder
#

If it's not a bot work I have an idea

Delete the role and create role again

slate swan
#

really depends on the situation guys! greate suggestions tho

fossil aspen
#

yea i tried this but it wont work

role_names = ("Co Host")
roles = tuple(get(ctx.guild.roles, name=n) for n in role_names)
for member in ctx.guild.members:
try:
await member.remove_roles(*roles)
except:
print(f"Couldn't remove roles from {member}")

error: Command raised an exception: NameError: name 'get' is not defined

#

@slate swan

#

@hybrid ravine

slate swan
#

just use the members property in a role obj?

hybrid ravine
hybrid ravine
# slate swan its an iterator so just iterate through it

<Message id=962162124321353868 channel=<TextChannel id=962147206276718652 name='old-yagami-over' position=0
nsfw=False news=False category_id=None> type=<MessageType.default: 0> author=<User id=920051517514453022 name='xylo' discriminator='1111' bot=False> flags=<MessageFlags value=0>>

im getting this as a return now

slate swan
fossil aspen
sick birch
pulsar thunder
#

I have some screenshots

#

Lemme put new ones

slate swan
pulsar thunder
#

?

#

Wait lemme send screenshots

hybrid ravine
#

is there a way to define "message" Outside of a function/params?

pulsar thunder
#

Below this is just the token and other stuff

slate swan
# pulsar thunder

not sure whats the problem but theirs allot of unnecessary converting of types here

sick birch
pulsar thunder
#

I'm planning on adding more stuff

sick birch
#

You aren't meant to instantiate discord.Member class yourself anyway

slate swan
# pulsar thunder
  1. the member class has a name attr which returns only the name of the member without discriminator
  2. the content attr in the message class already returns a string so does the name attr in the textchannel class
pulsar thunder
#

Ye I know I will remove it later

Did u mean user_message?

slate swan
#

pardon?

hybrid ravine
hybrid ravine
#

tbh not a big problem so idrm if theres no better way

pulsar thunder
#

I meant were u referring to the conversion happening for user_message?

sick birch
#

You're not supposed to instantiate a message class by yourself

slate swan
#

xylo are you trying to have a global base message by saving a string or?

hybrid ravine
#

actually yk what dw about it ima keep using it in the same way, its not that big of a deal

slate swan
#

😅

hybrid ravine
slate swan
pulsar thunder
slate swan
unkempt canyonBOT
#

@listen(name=None)```
A decorator that registers another function as an external event listener. Basically this allows you to listen to multiple events from different places e.g. such as [`on_ready()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_ready "discord.on_ready")

The functions being listened to must be a [coroutine](https://docs.python.org/3/library/asyncio-task.html#coroutine "(in Python v3.10)").

Example...
sick birch
slate swan
#

just use the name kwarg and set it to on_message

hybrid ravine
sick birch
#

I hope you're not following a youtube tutorial?

pulsar thunder
sick birch
#

I can sniff out youtube tutorials from miles away

sick birch
pulsar thunder
#

Saw it coz I didn't know how to add discord stuff in python without lagging

sick birch
#

Well, uh, ditch that code and start over before you get any more terrible code in

slate swan
slate swan
sick birch
#

What do you mean by "without lagging"?

pulsar thunder
#

Async function

slate swan
#

coroutines arent "laggy"

sick birch
#

How is an async function lagging?

slate swan
#

i am so confused

pulsar thunder
#

Not lag slow

sick birch
slate swan
sick birch
#

I'm guessing they tried to make a discord bot without using coroutines

pulsar thunder
#

Yes

sick birch
#

Which I don't even know is possible

slate swan
#

thats still not slow.

sick birch
#

Also while you're at it, get off replit too

pulsar thunder
#

Ok

sick birch
#

Then you can properly make discord bots

slate swan
#

its just one gets executed from top to bottom while one can get executed asynchronous hence the name async functions or coroutines

#

its just the manor of its execution!

sick birch
#

Not to mention regular functions block the event loop

slate swan
#

yep

sick birch
#

So you shouldn't mix and match if you can avoid it

pulsar thunder
#

So it make async faster right?

This is my first attempt

slate swan
#

no.

sick birch
#

Not necessarily

slate swan
#

search for the term asynchronous

sick birch
#

Async is used in I/O environments which isn't very demanding in the first place

#

So it can't be "faster"

#

Since you wait around 90% of the time

slate swan
pulsar thunder
#

Ok

#

I will

sick birch
#

It's like one of those choose your own adventure books

#

Vs reading the book from cover to cover

pulsar thunder
#

Hmm

sick birch
#

You go to page 5 and it says, if you want to do X, go to page 10, if you want to Y, go to page 25

slate swan
#

its like you have a collection of 5 episodes but one watched them by order and the other watches them unordered

sick birch
#

That's basically asynchronous

pulsar thunder
#

Oh

slate swan
#

and it can be executed many times unlike sync which you would have to wait for the function to stop its execution first

slate swan
#

not really

slate swan
sick birch
#

The reason discord.py is written asynchronously is that behind the scenenes, there are a few while True loops going on, and you can't keep something running with a while True loop in the same thread

pulsar thunder
#

Oh

primal cliff
#

hi how can i fix the error Attribute Error: "Bot" object has no attribute "has_permissions"

sick birch
primal cliff
slate swan
sick birch
#

That too

slate swan
#

lmao

sick birch
#

But primarily heartbeating and polling for events

slate swan
#

yeah

sick birch
#

both are while true if you do a lil source diving

slate swan
#

it does make sense allot of things come in to play

primal cliff
#

OHH it worked TYYYY

sick birch
#

Indeed. When you aren't using an event driven language (js for instance) you have to do things like that

pliant gulch
slate swan
#

yeah it would be annoying

#

imagine your bot not responding because the command is being used in another guild

hybrid ravine
#

async def get_channel(message):
guildID = message.get_guild.id()
ob = client.get_guild(guildID)
guild_name = guildID.name()
channels = []
with open(f'info/{guildID}/channels.txt', 'a') as txt:
channelcount = 0
for channel in ob.channels:
txt.write(str(channel.name) + '\n')
channelcount += 1
channels.append(channel)

would smth like this work? to get all the channel names in a guild and storer them?

primal cliff
#

uhh so the bot goes online but with the ban command it is not responding.

#

ban and kick*

primal cliff
slate swan
unkempt canyonBOT
primal cliff
primal cliff
unkempt canyonBOT
slate swan
unkempt canyonBOT
#

@command(*args, **kwargs)```
A shortcut decorator that invokes [`command()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.command "discord.ext.commands.command") and adds it to the internal command list via [`add_command()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin.add_command "discord.ext.commands.GroupMixin.add_command").
slate swan
#

im not sure if it takes positional arguments

#

and im not sure what the perm deco returns but you should put it above the function signature

hybrid ravine
primal cliff
#

it said:name "args" is not defined

hybrid ravine
hybrid ravine
slate swan
primal cliff
hybrid ravine
hybrid ravine
slate swan
primal cliff
primal cliff
hybrid ravine
#

async def ban then have ()?

#

the things that go inside

#

of those ()

#

are params/ paramaters

#

or passintg thru arguments i think

slate swan
slate swan
#

❤️

primal cliff
#

so is it possible to fix the args not defined error

hybrid ravine
primal cliff
#

ok

primal cliff
hybrid ravine
primal cliff
astral adder
#

🤔

hybrid ravine
primal cliff
hybrid ravine
#

dnt do that..

astral adder
hybrid ravine
#

u need to put *args and **kwargs in the function, not the decorators

primal cliff
slate swan
# primal cliff

why are you passing an unknwon amount arguments to a deco? it should be done in the parameters in the decorator and no need for it

slate swan
#

and i recommend you do learn a bit of python

primal cliff
#

so where should I put it

astral adder
#
import discord #Imports the discord module. from discord.ext import commands #Imports discord extensions. #The below code verifies the "client". client = commands.Bot(command_prefix='pb?') #The below code stores the token. token = "Your token" ''' The below code displays if you have any errors publicly. This is useful if you don't want to display them in your output shell. ''' @client.event async def on_command_error(ctx, error): if isinstance(error, commands.MissingRequiredArgument): await ctx.send('Please pass in all requirements 🙄.') if isinstance(error, commands.MissingPermissions): await ctx.send("You dont have all the requirements 😠") #The below code bans player. @client.command() @commands.has_permissions(ban_members = True) async def ban(ctx, member : discord.Member, *, reason = None): await member.ban(reason = reason) #The below code unbans player. @client.command() @commands.has_permissions(administrator = True) async def unban(ctx, *, member): banned_users = await ctx.guild.bans() member_name, member_discriminator = member.split("#") for ban_entry in banned_users: user = ban_entry.user if (user.name, user.discriminator) == (member_name, member_discriminator): await ctx.guild.unban(user) await ctx.send(f'Unbanned {user.mention}') return #The below code runs the bot. client.run(token) 
slate swan
#

what is this

astral adder
#

it seems weird In chat

sick birch
astral adder
slate swan
#

it looks like a nightmare to me

sick birch
#

it broke every single pep to exist

slate swan
#

it follows 9001 bro

sick birch
#

true

slate swan
#

;))

primal cliff
#

so where can I put it

slate swan
#

no where

#

that extra decorator isnt needed

primal cliff
#

ok the bot is running

#

but the commands arent working for some reasons

slate swan
#

all of them?

astral adder
#

Uh

primal cliff
slate swan
#

show code

primal cliff
#

ok then

primal cliff
slate swan
#

show how you invoked the command

primal cliff
#

wdym

slate swan
#

how you triggered the command

primal cliff
#

run button

slate swan
#

bro

primal cliff
#

oh wait I dont have the trigger

slate swan
#

bro

#

😭

primal cliff
#

I am dumb 😭

#

So I found a code on the internet I just need to know how to make the code work. Here is the code:

supple thorn
#

!d discord.Member.mention

unkempt canyonBOT
supple thorn
#

I don't know what the fuck is mention.mention though

fossil aspen
#

its the remove all members from a role i been trying for hours

final iron
#

Why not just delete the role?

#

Delete the role and recreate it

fossil aspen
#

im using role ids with something else

#

so i cant delete it

#

its for event purposes to remove all co hosts everytime the endevent cmd is used

final iron
#

!d discord.Role.members

unkempt canyonBOT
final iron
#

You can loop through the list of members that have the role

#

And then remove the role with

#

!d discord.Member.remove_roles

unkempt canyonBOT
#

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

Removes [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s from this member.

You must have the [`manage_roles`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_roles "discord.Permissions.manage_roles") permission to use this, and the removed [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s must appear lower in the list of roles than the highest role of the member.
final iron
#

It can make a lot of API calls though

fossil aspen
#

hm

#

idk much py so idek what to do to start lmfao

final iron
#

Depending on how many members have the role it can get you rate limited

#

You'll have to wait for someone else to come. I'm not really in the mood to help someone who doesn't know python

#

Sorry

pliant gulch
#

You could just clone the role, then delete the role

#

This would get rid of all the multiple API calls

final iron
#

Already gave him the suggestion

pliant gulch
#

Oh I didn't scroll up high enough

supple thorn
#

Make?

sterile imp
#

RuntimeError: Event loop is closed

spring flax
boreal ravine
slate swan
#

is it possible for the bot to send a message in all the guilds it is in
if yes can i have an example

boreal ravine
boreal ravine
slate swan
#

hmm

slate swan
slate swan
boreal ravine
slate swan
#

yea

#

what should i use then

#

rather than using ctx or message.send

boreal ravine
#
await guild.text_channels[0].send("yo")```
slate swan
#

k ty

crimson compass
#
async def on_message(message):
    if message.content.startswith('!ip'):
        embedVar = discord.Embed(title='`IP`', description= '**connect 51.210.223.221**', color=0xe8c02a)
        await message.channel.send(embed=embedVar)```
#

why doesn't this work?

boreal ravine
#

Which part of it doesn't work?

crimson compass
#

when i type !ip it doesnt send a message

boreal ravine
#

Does your bot have message intents?

crimson compass
#

used the wrong command 😆 sorry

boreal ravine
spring flax
#

is there a possible eh for ratelimits?

boreal ravine
spring flax
boreal ravine
#

Not really, d.py already handles rate limits for you

hasty bison
#

how do i send custom emojis?

cobalt jacinth
boreal ravine
#

best alternative is d.py

supple thorn
spring flax
#

get it by putting a \ in front of the emoji when sending it

cobalt jacinth
#

is this correct ?

supple thorn
#

Rather than using a on_message event

supple thorn
#

By danny

cobalt jacinth
#

should i stay with discord.py...have not had any issue till now.

boreal ravine
#

yes

hasty bison
formal basin
#

Why is “message” a invalid synax

slate swan
boreal ravine
formal basin
#

Wait no ctx?

boreal ravine
#

you're missing a comma next to discord.TextChannel

formal basin
#

Oh

slate swan
#

💀

formal basin
#

Ok

#

I def it in the ctx

boreal ravine
formal basin
#

Ok

#

1 sec

supple thorn
#

Is anyone else's discord dying wtf

slate swan
#

💀i doubt if you've correct intent

slate swan
boreal ravine
slate swan
#

wdym? ;'/ dying?

supple thorn
#

Example 😳

#

\😳

#

Turns to that

boreal ravine
#

\😳

formal basin
supple thorn
#

You can also get custom emojis

formal basin
supple thorn
slate swan
#

show intent @formal basin

supple thorn
slate swan
#

or like code ig if you're comfortable iwth it

slate swan
#

💀 that sounds like a problem tbh

supple thorn
#

It's been like this since earlier

formal basin
#

My intents are crazy

supple thorn
#

Started today

slate swan
formal basin
supple thorn
#

Sadly😔

slate swan
#

💀

#

there should be some option to fix it ig 💀

formal basin
#

Nvm fixed my error

slate swan
#

gg

supple thorn
slate swan
supple thorn
#

Just send the message variable

formal basin
#

Cause you can if you want

supple thorn
#

You don't need a f-string

supple thorn
formal basin
slate swan
#

ok ok cool

supple thorn
slate swan
#

first, i hope rest of ur intentation si correct

formal basin
slate swan
supple thorn
#

Even if you pinged someone using the command

formal basin
supple thorn
#

It'd ping them back

formal basin
#

It will send there message

slate swan
#

💀

supple thorn
#

Also why would they say {member.mention}?

slate swan
#

hmm

#

+1 ^

formal basin
#

And I’m just adding custom messages

slate swan
#

but here u are simply sending it in the channel :'/

supple thorn
supple thorn
#

Also why is everything inside your with open?

formal basin
#

What do I replace here

slate swan
#

eh? message.contex?

formal basin
slate swan
formal basin
unkempt canyonBOT
#
Nah.

No documentation found for the requested symbol.

slate swan
#

!d discord.Message.content

unkempt canyonBOT
slate swan
#

idk how to use this bot lol

formal basin
#

Well content doesn’t work

slate swan
#

i don't even know what u tryna do lol

#

i just told that there is nothing like message.context

#

there is message.content

formal basin
#

I just need to display my message into my json file

slate swan
#

this function welcome_setup, use pastebin if u want

#

!paste

unkempt canyonBOT
#

Pasting large amounts of code

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

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

slate swan
#

hmm

#

indentation doesn't look good to me

formal basin
#

Which line

slate swan
#

all

supple thorn
#

All

formal basin
#

How?

slate swan
#

intentation is gap of 4 space

maiden fable
slate swan
#

not 2

slate swan
formal basin
slate swan
#

idr number exactly nvm

maiden fable
#

.pep 9001

slate swan
maiden fable
#

Rip @lament depot

slate swan
#

:'/

slate swan
heavy folio
#

what

formal basin
#

What do I put there

slate swan
#

not message.contet or whatever

formal basin
slate swan
#

because it should be taken from the parameter that you've passed in the welcome_setup funciton

formal basin
#

Oh

#

Ok

#

I have a problem

#

It’s not sending the message

#

And I got no error

#

Anything wrong here

slate swan
#

its not a thing

formal basin
#

Ok how could I get the message

heavy folio
#

!d discord.TextChannel.fetch_message

unkempt canyonBOT
#

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

Retrieves a single [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") from the destination.
heavy folio
#

you fetch message from a text channel not guild

slate swan
#

and you need to send the message's content not the whole object

#

plus, what if the welcome message gets deleted

formal basin
heavy folio
#

what

formal basin
slate swan
heavy folio
formal basin
slate swan
#

hm catch me up

formal basin
#

I want to fetch my message from the json file

slate swan
#

what's currently in the welcome.json now?

slate swan
formal basin
#

Like a couple of channel ids and names also 1 message

formal basin
#

Done

#

Deleted it

slate swan
#

it should work now

formal basin
#

Ok

slate swan
#

@slate swan with open('jsonfile') will load the json too?

formal basin
#

Yes

slate swan
#

so it's the same as doing

json.load(file)

slate swan
visual island
slate swan
#

@formal basin did it work?

formal basin
slate swan
#

what's it doing

formal basin
slate swan
#

maybe because you have 2 message = ?

formal basin
#

Is that what I put await channel.send(f”{message}”)

blissful sparrow
#

Anyone know why I keep getting this error even though ive only done the login output?
TypeError: Client.event() missing 1 required positional argument: 'coro'

#
import discord
from discord.ext import commands

import requests
import json

token = 'token'
intents = discord.Intents(messages=True, guilds=True)


bot = commands.Bot(command_prefix='.', intents=intents)


@bot.event()
async def on_ready():
    print('The {0.user} bot has logged in!'.format(bot))



bot.run(token)
boreal ravine
slate swan
paper sluice
blissful sparrow
#

its in the docs

blissful sparrow
slate swan
#

@blissful sparrow reasoning why I don't recommend it is because you can only have one on_message.

blissful sparrow
#

im yet to add more functions but im trying to get the bot up first

slate swan
#

your error is @bot.event(), in discord.py for events you don't need the (), so it would be @bot.event
@blissful sparrow

paper sluice
#

^^^

blissful sparrow
#

Wow extra parenthesis wasted me 20 mins lmfao

#

thanks

slate swan
#

if you take another glance at the docs you can see that there are no parentheses either

#

sometimes you just gotta look it over again

paper sluice
slate swan
#

you dont "call" the events, they get triggered automatically

paper sluice
#

wait

#

i need glasses

slate swan
#

you don't need the () either way 🤣

paper sluice
#

i saw paren on on_ready and though it was the deco lmao

slate swan
slate swan
paper sluice
#

subclass and enjoy

slate swan
formal basin
slate swan
#

is it now

#

listen/event is a decorator, while on_message is an event function

formal basin
slate swan
#

no, its way different

#

yeah it is not the same thing

formal basin
#

And on_message stops your commands from working

formal basin
slate swan
#

where do you use listen? xd