#discord-bots

1 messages Β· Page 1005 of 1

slate swan
#

nvm, add a picture in a jpg file seemed weird

#

cool

thick basin
#
async with aiohttp.ClientSession() as session:
            async with session.get(str(url)) as resp:
                if resp.status != 200: 
                     return await ctx.send('L Bozo')
                data = io.BytesIO(await resp.read())
                await ctx.guild.edit(icon=data.read())
                await ctx.send("πŸ‘Œ")

I am trying to change the server icon where I give the gif url and it changes the icon to that but i am getting an error ValueError: Unsupported image type given
Can anyone tell what i am fucking up here

#

you clearly dont have PIL

cold sonnet
#

and why would you do that

thick basin
#

ok so did you restart your vscode?

#

after installation

thick basin
#

you got it now?

eager bough
#

who wanna make a discord bot with me (:

cold sonnet
thick basin
#

alr let me check once again

eager bough
#

Hi python

#

How are yall

thick basin
olive osprey
unkempt canyonBOT
eager bough
#

):

#

Who want's to make a discord bot with me in python?

olive osprey
#

Focused on what?

eager bough
#

wdym

eager bough
#

or soft ban

thick basin
#

nooo not that

cold sonnet
#

you should only have a discord.File instance

thick basin
eager bough
#

oh

thick basin
cold sonnet
#

where do you get the GIF from

eager bough
#

Hi

cold sonnet
#

!d discord.Guild.edit

unkempt canyonBOT
#
await edit(*, reason=..., name=..., description=..., icon=..., banner=..., splash=..., discovery_splash=..., community=..., afk_channel=..., owner=..., afk_timeout=..., ...)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Edits the guild.

You must have the [`manage_guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_guild "discord.Permissions.manage_guild") permission to edit the guild.

Changed in version 1.4: The rules\_channel and public\_updates\_channel keyword-only parameters were added.

Changed in version 2.0: The discovery\_splash and community keyword-only parameters were added.

Changed in version 2.0: The newly updated guild is returned...
eager bough
#

Heey can someone help me?

olive osprey
olive osprey
#

what

cold sonnet
#

icon kwarg accepts byte like objects

eager bough
#

No onee can help me?

thick basin
#

hmmm i just read that in docs i am running once again

cold sonnet
#

I think io.BytesIO is a byte like object itself

#

no need to read

eager bough
#

ok ok

cold sonnet
thick basin
#

makes sense

cold sonnet
#

just if someone will code a bot with you

eager bough
eager bough
cold sonnet
#

and there's a high chance nobody will do that

placid skiff
#

in this channel we talk and help others about discord bot development, usually we don't talk about our projects or ask help for them

slate swan
#

Hi

#

Its connected with github repo

vale wing
#

Case matters: from PIL import Image

daring olive
# eager bough mhm

you can discuss and ask questions about discord bots here, but this server is not for recruiting people to work with you or to teach you

cloud dawn
#

@daring olive Are you still contributing to @unkempt canyon ?

eager bough
#

If you are using disnake you can make / commands with this!

@bot.slash_command(name='')
daring olive
#

uhhhhh very occasionally and mostly on small cosmetic things

#

or things related to moderation

eager bough
#

you can add disnake by

#
import disnake
vale wing
vale wing
#

You had from PIL import image

velvet haven
#

how do i delete all the messages in a channel

placid skiff
#

bruh

#

!d discord.TextChannel.delete_messages

unkempt canyonBOT
#

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

Deletes a list of messages. This is similar to [`Message.delete()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message.delete "discord.Message.delete") except it bulk deletes multiple messages.

As a special case, if the number of messages is 0, then nothing is done. If the number of messages is 1 then single message delete is done. If it’s more than two, then bulk delete is used.

You cannot bulk delete more than 100 messages or messages that are older than 14 days old.

You must have the [`manage_messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_messages "discord.Permissions.manage_messages") permission to use this...
thick basin
# vale wing What is "Content-Type" header

nevermind, I was using a www.tenor.com/view/ link which I shouldn't and I was blaming the code
When I gave the image url instead of web url as an argument, it changed the server icon

maiden fable
#

?

slate swan
#

How can I make it reply to the sender's message?

olive osprey
maiden fable
#

Yea, uhh, that

slate swan
#

example:

quick gust
#

then u make an embed

slate swan
#

can you please edit the code as needed?

#
@bot.command()
async def avatar(ctx, member: discord.Member  = None):
    if member == None:
        member = ctx.author
    await ctx.reply()
    embed = discord.Embed(colour=discord.Color.light_grey(), title=f"Avatar of {member.name}", url = member.avatar_url)
    embed.set_image(url = member.avatar_url)
    await ctx.send(embed = embed)```
olive osprey
slate swan
#

thx!

#

what to do? no discord module

#

where?

slate swan
#

I already downloaded

slate swan
#

already rebooted

maiden fable
#

@slate swan what is yr ide

slate swan
#

Visual Code Studio

maiden fable
#

Hm do u have two Python installations?

slate swan
#

idk

maiden fable
#

Just see from control panel and programs and features option

#

see if it shows two Python versions

slate swan
maiden fable
slate swan
#

second

slate swan
#

Yes

#

yes ik

#

I loss many brain cells during making

#

What's ur issue

#

No

#

It's easy

#

What's hard in that?

#

Any particular thing?

paper sluice
#

what have you tried till now?

drifting arrow
#

How do I make a bot set a channel to private?

#

a voice channel*

flint isle
#

what is the doc for reacting to a message

maiden fable
#

!d discord.Message.add_reaction

unkempt canyonBOT
#

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

Adds a reaction to the message.

The emoji may be a unicode emoji or a custom guild [`Emoji`](https://discordpy.readthedocs.io/en/master/api.html#discord.Emoji "discord.Emoji").

You must have the [`read_message_history`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.read_message_history "discord.Permissions.read_message_history") permission to use this. If nobody else has reacted to the message using this emoji, the [`add_reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.add_reactions "discord.Permissions.add_reactions") permission is required.

Changed in version 2.0: `emoji` parameter is now positional-only.

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

ty

slate swan
# maiden fable !d discord.Message.add_reaction

How do I add a reaction to a message?
There are a few ways to do it, firstly, you need the emoji you want.
For basic (non custom) emojis, this can be either:
The Codepoint \u2705
The Raw Unicode joy
The Name \N{MAN IN BUSINESS SUIT LEVITATING}
For custom emojis, you will need to specify it in a format similar to:
name:id for static emojis, or a:name:id for animated emojis.
Note that you must NOT have the <> in the reaction.
Or an alternative way,
discord.PartialEmoji(is_animated (True or False), name, id)

How can I use to add a reaction?
await message.add_reaction(<your emoji>)

use R.danny πŸ˜”

maiden fable
#

Nvm

paper sluice
#

@unkempt canyon superior

maiden fable
#

I won't say a word

somber heath
#

How can I make my Discord bot ping a pinged person? For example, User1 pings User2 in a punch command, and the bot sends: @User1 punched @User2!. How can I do that? But I also want the bot to send a random answer after that, for example, User2 survived; User2 died and smth. Btw, everything is gonna be in an embed.

Using discord.py

paper sluice
#

!d discord.Member.mention

unkempt canyonBOT
maiden fable
#

@somber heath just add : discord.Member at the end of the arg, that is, typehint it with discord.Member and u can then do user.mention

slate swan
#

Back

maiden fable
#

?

slate swan
#

That bold title

drifting arrow
#
Traceback (most recent call last):
  File "c:\Users\Me\Desktop\gnomesbot\Discordbot.py", line 1, in <module>
    import discord, asyncio, os
  File "C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\__init__.py", line 25, in <module>        
    from .client import Client
  File "C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 53, in <module>
    from .webhook import Webhook
  File "C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\webhook\__init__.py", line 12, in <module>
    from .async_ import *
  File "C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\webhook\async_.py", line 46, in <module>  
    from ..channel import PartialMessageable
ImportError: cannot import name 'PartialMessageable' from 'discord.channel' (C:\Users\Me\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\channel.py)

Why am I getting this error? My bot was working earlier and I havent changed anything ;-;

maiden fable
arctic gyro
#

Hi , im on replit and im experiencing this error whenever I try to run my bot . Pls help

paper sluice
#

dont use replit

slate swan
drifting arrow
maiden fable
#

You were ratelimited

maiden fable
drifting arrow
#

Why do I need to reinstall python? it was working earlier.

maiden fable
#

@drifting arrow u got from Microsoft Store?

drifting arrow
#

yes

#

but that still doesnt help solve my issue..

slate swan
#

Download from google

maiden fable
#

Well, that is the issue

somber heath
#

works for me

slate swan
drifting arrow
#

I'll do it since then if the issue persists I can say I did it. But I dont believe it could be since everything was fine for the last year..

#

so why would it suddenly break?

slate swan
#

Replit suks

somber heath
#

Not for me

#

But it has 24/7 hosting

flint isle
# unkempt canyon

do i have to specify the message id in this code?

if reaction.emoji ==  'βœ…':
                    print('checkmark detected')
                    await ctx.send(f'checkmark detected! it is in {msg.id}')
                    await add_reaction(βœ…,)
                    # We break since we already found the check, heading to next message
                    break
slate swan
#

Try running ur bot on more than 10 servers then you'll see

maiden fable
slate swan
#

Also anyone can acces ur token

#

If u didn't buy that premium stuff

maiden fable
slate swan
#

anyone can copy ur code

flint isle
slate swan
#

Go up ^

#

Scroll

maiden fable
#

@drifting arrow DMed u smth

slate swan
#

..

#

πŸ‘€

flint isle
# maiden fable ```py msg = await ctx.send await msg.add_reaction() ```

i got this error

β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘
β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘
β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘
β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘
β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘
β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘
β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘
β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘
β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘
β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘
β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆ
β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘
β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘
Whiskey Bot
Developed by: David Powell
Starting Bot

Connecting to Discord API.
Please Wait
Connected!
Bot is ready.
Waiting For Commands
Running Search
$allmsg
GG @flint isle, you just advanced to level 6!
🦊
$allmsg
checkmark detected! it is in 967915351159500892
checkmark detected! it is in 967915351541182545
checkmark detected
Ignoring exception in command allmsg:
Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "<string>", line 90, in msg
TypeError: object method can't be used in 'await' expression

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

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/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: object method can't be used in 'await' expression
maiden fable
#

show code

flint isle
#

oh yeah 1 sec sry

slate swan
#

Code art cool

flint isle
#
    for msg in msgs:
        print(msg.content)
        if msg.reactions:
            for reaction in msg.reactions:
                if reaction.emoji ==  'βœ…':
                    print('checkmark detected')
                    await ctx.send(f'checkmark detected! it is in {msg.id}')
                    msg = await ctx.send
                    await msg.add_reaction('🦊')
                    # We break since we already found the check, heading to next message
                    break
maiden fable
#

agreed

flint isle
maiden fable
flint isle
# slate swan Nice bot startup

yeah the code is kinda spagette tho lol

import pause as time
print('β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘')
time.sleep(.05)
print('β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆ')
time.sleep(.05)
print('β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘')
time.sleep(.05)
print('β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘')
time.sleep(.05)
print('Whiskey Bot')
time.sleep(.1)
print('Developed by: David Powell')

thts what it turned out as

flint isle
maiden fable
maiden fable
#

wait wait wait

flint isle
maiden fable
#
    for msg in msgs:
        print(msg.content)
        if msg.reactions:
            for reaction in msg.reactions:
                if reaction.emoji ==  'βœ…':
                    print('checkmark detected')
                    await ctx.send(f'checkmark detected! it is in {msg.id}')
                    await msg.add_reaction('🦊')
                    # We break since we already found the check, heading to next message
                    break
#

this should be the final code

#

since u wanna react to the message with the checkmark reaction, right?

slate swan
#

List compre

maiden fable
#

cba to convert it to a list comp, sorry

maiden fable
#

yea that should be it

somber heath
slate swan
#

def noob(arg : discord.Member)

flint isle
#

It delays the line so each waits a really short time to print the next

maiden fable
somber heath
#

Oh, so I need to specify a user? Or no?

maiden fable
#

Yea

somber heath
#

oof

paper sluice
somber heath
#

I mean like this, but with mentions

#

without the footer

spring flax
#

for bots where are the logging events normally sent? If it's all to one file, won't it be clogged up super quick?

paper sluice
#

maybe clear the file after sometime?

maiden fable
#

the logging module events or...

spring flax
#

yeah

paper sluice
#

!src

unkempt canyonBOT
maiden fable
#

Ah, well those are sent in the console by default

spring flax
#

logging.info when a command is ran or whatever

spring flax
paper sluice
#

hold up, ill look up how @unkempt canyon does it

maiden fable
#

Best of Luck

unkempt canyonBOT
#

bot/log.py lines 56 to 61

if constants.FILE_LOGS:
    log_file = Path("logs", "bot.log")
    log_file.parent.mkdir(exist_ok=True)
    file_handler = handlers.RotatingFileHandler(log_file, maxBytes=5242880, backupCount=7, encoding="utf8")
    file_handler.setFormatter(log_format)
    root_log.addHandler(file_handler)```
somber heath
unkempt canyonBOT
#

bot/log.py lines 105 to 116

def _set_trace_loggers() -> None:
    """
    Set loggers to the trace level according to the value from the BOT_TRACE_LOGGERS env var.

    When the env var is a list of logger names delimited by a comma,
    each of the listed loggers will be set to the trace level.

    If this list is prefixed with a "!", all of the loggers except the listed ones will be set to the trace level.

    Otherwise if the env var begins with a "*",
    the root logger is set to the trace level and other contents are ignored.
    """```
spring flax
#

what is __name__ again?

maiden fable
#

the name of the file being executed

#

!if-name-main

unkempt canyonBOT
#

if __name__ == '__main__'

This is a statement that is only true if the module (your source code) it appears in is being run directly, as opposed to being imported into another module. When you run your module, the __name__ special variable is automatically set to the string '__main__'. Conversely, when you import that same module into a different one, and run that, __name__ is instead set to the filename of your module minus the .py extension.

Example

# foo.py

print('spam')

if __name__ == '__main__':
    print('eggs')

If you run the above module foo.py directly, both 'spam'and 'eggs' will be printed. Now consider this next example:

# bar.py

import foo

If you run this module named bar.py, it will execute the code in foo.py. First it will print 'spam', and then the if statement will fail, because __name__ will now be the string 'foo'.

Why would I do this?

β€’ Your module is a library, but also has a special case where it can be run directly
β€’ Your module is a library and you want to safeguard it against people running it directly (like what pip does)
β€’ Your module is the main program, but has unit tests and the testing framework works by importing your module, and you want to avoid having your main code run during the test

spring flax
#

so if I have a logging config in my main file, it's carried to other files?

#

like py logging.basicConfig(level=logging.DEBUG)
This is in my main file, so i have to keep writing it for each cog file?

paper sluice
#

no

#

just make a function/class and call it

pliant gulch
#

You could put it in your root namespace file

paper sluice
#

set the level there

pliant gulch
#

It will carry across all your other package files

paper sluice
spring flax
#

and if i have 5 cog files and have in each, they all get printed to the same terminal right?```py
log = logging.getLogger(name)

pliant gulch
paper sluice
#

🀯

pliant gulch
#

Or should be? I’m not confident so

#

If you want a singleton logger you should be using loguru

flint isle
#

umm how do i refrence a custom emoji when i add a reaction? i forgot how

maiden fable
#

by adding a \

#

in front of the emoji name and getting the name and id

slate swan
#

this way ^

flint isle
#

how do i get that number lmao

slate swan
flint isle
#

oh so
/"theemoji

maiden fable
#

mhm

slate swan
#

yeah

flint isle
#

k thx

slate swan
#

:")

little ivy
#

short question, how can i make these 2 thogether?

#

so i would like have a list of "bad words" that trigger the whole action.

flint isle
slate swan
#

but for a simple one. just ask any of your friend to do that who've nitro

paper sluice
#
list_of_bad_words = []
any(word in message.content for word in list_of_bad_words)

@little ivy
please name the param message instead of ctx

slate swan
flint isle
#

cause none of my friends have nitro

slate swan
#

!d discord.Guild.emojis returns a list of emojis you can use for loop on it

slate swan
unkempt canyonBOT
slate swan
#

ID from url, lol

#

and print them all

little ivy
slate swan
paper sluice
slate swan
spring flax
#

I've seen people use log.info in bots, but when it's done all disnake internal events show up also

paper sluice
drifting arrow
#

How do I make it so users can see a private voice channel?

sick birch
#

Don’t make it private

drifting arrow
#

Well I want to lock everybody out from entering it and then add a feature so you can invite people to it

#

No. thats for text channels.

#

I want voice channels lol

#

I want it to be a public feature tho. so I want to add people to the permissions list using a command

#

idk

#

The idea is, a user makes a new voice channel using a command, then if they lock it, they can invite people, which basically adds those invited to the permissions list so they can view the channel and join

#

also idk what stages is

foggy zealot
#

hello there...

import discord
import asyncio
from discord import client
from discord.ext import commands
from pythonping import ping
def delays():
    response_list2 = ping('35.158.5.187', size=40, count=10)
    ms2 = response_list2.rtt_avg_ms
    response_list = ping('168.119.193.207', size=40, count=10)
    ms = response_list.rtt_avg_ms

    if ms>0 and ms<=33:
        desc='🟒 Online'
    elif ms>33 and ms<66:
        desc='🟑 Minor Outage'
    elif ms>=66:
        desc='🟠 Outage'
    else:
        desc='πŸ”΄ Offline'

    if ms2>0 and ms2<=33:
        desc='🟒 Online'
    elif ms2>33 and ms2<66:
        desc='🟑 Minor Outage'
    elif ms2>=66:
        desc='🟠 Outage'
    else:
        desc='πŸ”΄ Offline'

bot = commands.Bot(command_prefix='>')
client = discord.Client()

class Client(discord.Client):
    async def on_ready(self):
        print('Logged on as {0}!'.format(self.user))

    async def on_message(self, message):
        print('Message from {0.author}: {0.content}'.format(message))

async def my_background_task():
    await client.wait_until_ready()
    while not client.is_closed():
        message = await client.get_channel(968499225845432330).fetch_message(968499691446755379)
        await message.edit(embed=discord.Embed(title="Statuses", description=(f"**RDP**: {desc} -  [`{ms}ms`]\n**Database**: {desc} - [`{ms2}ms`]"), color=0x1eff00))
        embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/912797781888999438/964829134553493534/Comp_1.gif")
        embed.set_footer(text="Updates every 5 seconds")
        delays()
        await ctx.send(embed=embed)
        await asyncio.sleep(5)
bg_task = client.loop.create_task(my_background_task())

client.run('token')

this should update the embed with new ms delay but it doesn't... any ideas why?

drifting arrow
#

but thats for text channels. I'm looking for voice channels.

#

Change the ; to :

#

yes

rare saddle
#

How to send a video that is on a PC to embed?

foggy zealot
rare saddle
cloud dawn
unkempt canyonBOT
#

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

This function returns the class instance to allow for fluent-style chaining.
slate swan
#

how can I create an @command line that can tell the bot that the commando must not work against that role?

cloud dawn
cloud dawn
rare saddle
slate swan
#

how can I create an @command line that can tell the bot that the commando must not work against that role?

#

pls guys

slate swan
#

how?

slate swan
cloud dawn
#

!d discord.ext.commands.check

unkempt canyonBOT
#

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

These checks should be predicates that take in a single parameter taking
a [`Context`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Context "discord.ext.commands.Context"). If the check returns a `False`-like value then
during invocation a [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure") exception is raised and sent to
the [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") event...
cloud dawn
#

There is an example if you click on the link.

slate swan
#

role for the members @commands.has_role(968314252202999889)

#

the command must not work against the role I am indicating with id @discord.ext.commands.check(968314247035650139)

cloud dawn
#

Yeah so you got to make a custom check.

drifting arrow
#

Anyway

#

Figured it out. Didnt need stage

eager bough
#

Hi

foggy zealot
eager bough
#
path = 'ur path'
embed = discord.Embed(title='')
embed.set_image(url='Ur image url here')
  await ctx.send(embed=embed)
#

try that

#

@rare saddle

eager bough
#

...

rare saddle
eager bough
foggy zealot
#

thats how it works on webhooks

split solstice
foggy zealot
#

dunno if its same on dpy....

mellow mountain
#
@bot.command()
@commands.cooldown(1, 86400, commands.BucketType.user)
async def daily(ctx):

So i have a command named daily with a 24h cooldown. Is it possible to reset the cooldown on midnight every day for everyone?

daily.reset_cooldown(ctx) resets the cooldown for the executing user, right? But not for everyone.

eager bough
#

huh

foggy zealot
# eager bough (:
import discord
import asyncio
from discord import client
from discord.ext import commands
from pythonping import ping
def delays():
    response_list2 = ping('35.158.5.187', size=40, count=10)
    ms2 = response_list2.rtt_avg_ms
    response_list = ping('168.119.193.207', size=40, count=10)
    ms = response_list.rtt_avg_ms

    if ms>0 and ms<=33:
        desc='🟒 Online'
    elif ms>33 and ms<66:
        desc='🟑 Minor Outage'
    elif ms>=66:
        desc='🟠 Outage'
    else:
        desc='πŸ”΄ Offline'

    if ms2>0 and ms2<=33:
        desc='🟒 Online'
    elif ms2>33 and ms2<66:
        desc='🟑 Minor Outage'
    elif ms2>=66:
        desc='🟠 Outage'
    else:
        desc='πŸ”΄ Offline'

bot = commands.Bot(command_prefix='>')
client = discord.Client()

class Client(discord.Client):
    async def on_ready(self):
        print('Logged on as {0}!'.format(self.user))

    async def on_message(self, message):
        print('Message from {0.author}: {0.content}'.format(message))

async def my_background_task():
    await client.wait_until_ready()
    while not client.is_closed():
        message = await client.get_channel(968499225845432330).fetch_message(968499691446755379)
        await message.edit(embed=discord.Embed(title="Statuses", description=(f"**RDP**: {desc} -  [`{ms}ms`]\n**Database**: {desc} - [`{ms2}ms`]"), color=0x1eff00))
        embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/912797781888999438/964829134553493534/Comp_1.gif")
        embed.set_footer(text="Updates every 5 seconds")
        delays()
        await ctx.send(embed=embed)
        await asyncio.sleep(5)
bg_task = client.loop.create_task(my_background_task())

client.run('sussy token here')

why this doesnt update every 5s?

eager bough
#

why tf ping me

#

im alr in chat

#

tf

foggy zealot
#

misteak

eager bough
#

mhm

#

ok gimme a sec ima look at the code

foggy zealot
#

ight

#

also footer doesnt show up...

eager bough
#

im not familier with that package you are using but here are somethings you can try instead of ```py
client.get_channel(968499225845432330).fetch_message(968499691446755379)

Use This:
foggy zealot
#

it works alright... just it doesn't update

eager bough
#
await (client.get_channel(...)).send(...)
#

prob put await inside the ()

#

and also use

#
@task.loop(...)
#

@foggy zealot

foggy zealot
#

im new in d.py i dont knoew these stuff... Sip

eager bough
#

Okay.

#

just use task.loop in ur event or funtion

#

should be easy enough

tacit token
#

hi, how can i get the on member update if the username changed print username changed if the nickname nickname changed

eager bough
#

hm

quaint epoch
#

!d disnake.on_member_update

unkempt canyonBOT
#

disnake.on_member_update(before, after)```
Called when a [`Member`](https://docs.disnake.dev/en/latest/api.html#disnake.Member "disnake.Member") updates their profile.

This is called when one or more of the following things change:

β€’ nickname

β€’ roles

β€’ pending...
foggy zealot
tacit token
eager bough
quaint epoch
eager bough
#

u canot make that code in 1 day

unkempt canyonBOT
#

discord.on_member_update(before, after)```
Called when a [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") updates their profile.

This is called when one or more of the following things change:

β€’ nickname

β€’ roles

β€’ pending...
tacit token
quaint epoch
#

disnake and discord are mostly the same in terms of api reference and docs

eager bough
#

or copying and pasting

foggy zealot
slate swan
#

how can I create an @command line that can tell the bot that the commando must not work against that role?

eager bough
#

ok...

cloud dawn
quaint epoch
#

elaborate futher plz

cloud dawn
cloud dawn
eager bough
#

huh

#

what does he mean then

quaint epoch
#

so it should not allow that role to access the command?

#

!d disnake.ext.commands.check

unkempt canyonBOT
#

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

These checks should be predicates that take in a single parameter taking
a [`Context`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.Context "disnake.ext.commands.Context"). If the check returns a `False`-like value then
during invocation a [`CheckFailure`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.CheckFailure "disnake.ext.commands.CheckFailure") exception is raised and sent to
the [`on_command_error()`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.disnake.ext.commands.on_command_error "disnake.disnake.ext.commands.on_command_error") event...
quaint epoch
#

just use this

cloud dawn
eager bough
#

ok...

tacit token
#

so i have display name but i need username

quaint epoch
quaint epoch
unkempt canyonBOT
tacit token
slate swan
# eager bough ```py @commands.has_role() ```

I mean that the bot must not be used against an administrative role i.e. for example I did a dm command only for user warnings etc but it is used for bursts of fun by the staff so I am looking for a way that the bot does not send me messages or be used against me

eager bough
slate swan
#

like dyno when you use a commando against a staffer of the same role it does nothing

quaint epoch
slate swan
eager bough
#

then tell him that not me

#

anyways where was i

#

ahh yes

#

i remember

cloud dawn
unkempt canyonBOT
#
Not gonna happen.

No documentation found for the requested symbol.

eager bough
#

.

quaint epoch
#

!d discord.Member.guild_permissions

unkempt canyonBOT
#

property guild_permissions```
Returns the member’s guild permissions.

This only takes into consideration the guild permissions and not most of the implied permissions or any of the channel permission overwrites. For 100% accurate permission calculation, please use [`abc.GuildChannel.permissions_for()`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.GuildChannel.permissions_for "discord.abc.GuildChannel.permissions_for").

This does take into consideration guild ownership, the administrator implication, and whether the member is timed out.

Changed in version 2.0: Member timeouts are taken into consideration.
quaint epoch
#

yeah, here you go

cloud dawn
#

!d discord.Permissions.administrator

unkempt canyonBOT
#

Returns True if a user is an administrator. This role overrides all other permissions.

This also bypasses all channel-specific overrides.

quaint epoch
#

just run a check

slate swan
#

im here

eager bough
cloud dawn
#

Personally would use hierarchy to check.

eager bough
#

yh lol

cloud dawn
#

!d discord.Member.top_role

unkempt canyonBOT
#

property top_role```
Returns the member’s highest role.

This is useful for figuring where a member stands in the role hierarchy chain.
eager bough
#

Nevermind

regal pulsar
#

how would i get a message by its id from a dm

eager bough
#
@client.command(name='Fancy-Embed')
@commands.has_role(123456789)
async def embed(ctx, imput: str):
  embed = disnake.Embed(title=f'{imput}', description='This Is A Fancy Embed ish..', color = disnake.Color.random())
  await ctx.reply(embed=embed)

trying to make a fancy embed lol

regal pulsar
cloud dawn
regal pulsar
cloud dawn
regal pulsar
#

i have its id so

eager bough
regal pulsar
#
message = discord.utils.get(await message.channel.history(limit=100).flatten(), author=dank_memer)
#

working with this rn

eager bough
#

Ahhh

regal pulsar
#

then i get this

eager bough
#

send error

regal pulsar
#
<Message id=968581779214729226 channel=<DMChannel id=968564134918623272 recipient=<User id=770444560215572481 name='Dank Memer' discriminator='8805' bot=True>> type=<MessageType.default: 0> author=<User id=770444560215572481 name='Dank Memer' discriminator='8805' bot=True> flags=<MessageFlags value=0>>
regal pulsar
eager bough
#

...

eager bough
#

what are u trying to do? purge messages?

regal pulsar
#

i need the message's content

eager bough
#

do you want it to purge message?

regal pulsar
#

no

eager bough
#

Then what

regal pulsar
#

i just need the last message sent in that dm

eager bough
#

your gonna need

cloud dawn
regal pulsar
eager bough
#

mhm

regal pulsar
#

my account is like 2 years old

eager bough
#

looks like it

regal pulsar
#

id rather not have it banned

slate swan
#

Why'd you read Dank Memer DM messages in that case?

regal pulsar
slate swan
#

Hmmm

#

Still suspicious if you want my opinion

regal pulsar
#

πŸ˜”

eager bough
slate swan
#

You can't

cloud dawn
eager bough
#

y

regal pulsar
#

cant

slate swan
#

As simple as that

regal pulsar
#

they stopped giving them out'

slate swan
#

They stopped giving it around 2 years ago

eager bough
#

):

regal pulsar
eager bough
cloud dawn
#

!d discord.DMChannel

unkempt canyonBOT
#

class discord.DMChannel```
Represents a Discord direct message channel.

x == y Checks if two channels are equal.

x != y Checks if two channels are not equal.

hash(x) Returns the channel’s hash.

str(x) Returns a string representation of the channel
slate swan
#

Due to people spamming the queue with spam bots just because they wanted more pixels on their profile.

cloud dawn
#

!d discord.DMChannel.history

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...
cloud dawn
slate swan
#

They created a bot, created 76 servers, made the bot join these 76 servers and applied for the verification to get the badge.

eager bough
#

k

slate swan
slate swan
#

Waiting time to get verified went far too high due to this and they decided to stop giving it.

eager bough
#

he did it not me

slate swan
eager bough
#

nice

slate swan
#

No, seems like it also was 76

eager bough
regal pulsar
#

ill try it

slate swan
#

Because it's not relevant and don't want to "advertise" it

eager bough
slate swan
#

I have DMs closed and it will stay like that

eager bough
#

mhm

regal pulsar
#

hmm

eager bough
#

@regal pulsar did it help you

regal pulsar
eager bough
#

ok

#

ugh

regal pulsar
# eager bough ugh
async for msg in DMChannel.history(limit=1):
    await DMChannel.send(user, message.content)
eager bough
#

so it worked

regal pulsar
#

how do i specify which dm channel

#

like for each dm the bot gets

eager bough
regal pulsar
#

i see

eager bough
#

mhm

eager bough
slate swan
#

No need to await when you use get_

eager bough
#

oh ok

slate swan
#

Only need when you use fetch_

eager bough
#

alr

slate swan
#

Which makes an API call

eager bough
#

ik lol y be so spacific

slate swan
#

Because others might not know :)

eager bough
#

...

eager bough
slate swan
#

More specifically the one you were giving that snippet

eager bough
#

huh

regal pulsar
#

uh wait

slate swan
#

Always good to get some more information poggythumbsup

regal pulsar
#

how do i get the id of the dm channel πŸ’€

slate swan
#

It's the user ID

regal pulsar
#

oh

#

but it returns none when i try it

slate swan
#

Then it's not in cache

eager bough
slate swan
#

Consider using

c = client.get_channel(...) or await client.fetch_channel(...)
#

Which will first try to get from cache with get_channel and if it returns None it will use fetch_channel and make an API call.

regal pulsar
#

i see

slate swan
#

No, there's just nothing to say

eager bough
#

So will you add me

slate swan
#

No, that's also why I have friend requests disabled

regal pulsar
#

im getting an unknown channel error

regal pulsar
slate swan
#

I joined the Converso in the middle, may I get an overview of your code right now?

eager bough
#

no

slate swan
#

If you want to send a private message and you have the user ID, consider using get_user and use .send() on the object.

eager bough
#

nope

#

will not work

eager bough
#

you need to do this

slate swan
#

Here is an example

#

Which clearly shows how to do it and that it will work.

tacit token
#

Guys, how can i make this command to def? So the code and what i want

message_counter = 0

@cord.event
async def on_message(message):
    global message_counter
    message_counter += 1

So if i write !info the Bot print 1110 message (of every server)

eager bough
#
(client.get_user(...)).send(...)
#

@slate swan

regal pulsar
slate swan
#

That's literally what I've said

eager bough
regal pulsar
#

it basically forwards the message to me

slate swan
#

Then just use await user.send(...)

#

If user is actually your ID you're putting in

regal pulsar
#

oh yeah

#

but accessing the message is the problem

slate swan
#

And the channel is just message.channel, no need to fetch it.

regal pulsar
#

i see

#

oh yeah πŸ€¦β€β™‚οΈ

eager bough
#

ctx.channel()

slate swan
#

Not a function and in an on_message event there is just a message argument being passed

regal pulsar
#

oh

#

it works

eager bough
regal pulsar
#

how did i waste so much time on that ;/

slate swan
#

Not for what they want to do

eager bough
#

...

regal pulsar
#

thanks guys πŸ‘‹

slate swan
#

A command for that won't bring anything

eager bough
#

np

slate swan
#

No problemo

eager bough
#

on yt

slate swan
#

I have other things to do

olive osprey
#

what

eager bough
#

shush

tacit token
#

guys how can i get avatar update with on_member_upadte?

slate swan
#

Compare the avatar before and after

#

If they're not the same, it got changed

tacit token
#

and how? before.avatar_url?

slate swan
#

Yup

tacit token
#

and await ctx.send(f"{before.avatar_url} {after.avatar_url}")?

slate swan
#

That will print the avatar before and after the change

tacit token
#

and how can i print the 2 avatar

#

same with MEE6 logging

tacit token
#

ok i try it

slate swan
#

Just note that the avatar URL of before might return error 404 since the avatar will get removed from Discord's CDN

elder narwhal
#

Hello

eager bough
#

hello

#

Who want's to be friends ?

slate swan
#

If I remember correctly MEE6 has a manual caching method to keep it

tacit token
#

yeah but deleted it after 30 days (the discord say delete after 30 day this information)

eager bough
#

.

elder narwhal
#

principles to make a bot I don't know anything about python or programming itself and I would like to make a discord bot

slate swan
#

I think it's more like a few minutes/hours

eager bough
#

please tell me there is a differnce between hacking and programing

unkempt canyonBOT
#
Resources

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

slate swan
#

Will help you out for learning Python

velvet haven
#

can i ask a really dumb question?

slate swan
#

Any question can be asked fastnod

velvet haven
#

what's the purpose of slash commands

elder narwhal
velvet haven
#

when u can use normal commands

#

aren't they just same

slate swan
#

Well you can't anymore depending on if you have your bot verified or not and if you have the message intent

#

Whereas for slash commands there are awesome things coming like a permission system where the server owner/administrators can set which user can use which command and in what channel.

velvet haven
#

oh

slate swan
#

Basically slash commands provide, and even more later, a better and easier customization for your commands

velvet haven
#

we just have to enabble that option in developer portal to use it right?

slate swan
#

There is no option to enable, you can directly use them

eager bough
#

@slate swan would this work?

@client.command(name='message')
async def message(ctx, imput:str, *, member : disnake.Member):
  await ctx.send(f"Susscefuly sent a message to {member.mention}")
#

oh i need to

slate swan
eager bough
#

define imput

#

yep

slate swan
#

I would invert member and input parameters

eager bough
#

ok

fervent vapor
#

how would i get the link of a voice channel

slate swan
#

!d discord.VoiceChannel.jump_url # Not that it's only in 2.0

unkempt canyonBOT
slate swan
#

!d discord.VoiceChannel.mention # This would mention the channel so that you can click on it to join, kind of same as above

unkempt canyonBOT
fervent vapor
slate swan
#

A link such as?

heady sluice
#

voice channels don't have URLs...

fervent vapor
slate swan
#

They do

heady sluice
slate swan
#

https://discord.com/channels/guild_id/channel_id if you want the structure, doesn't seem like there is an attribute for it

fervent vapor
#

oh and then i can just use vars to fill in the guild id and chanel id

#

i want the link because then i can put it into the url of an embed and the user just has to click teh title to get an invite to the call

heady sluice
#

that's smart

slate swan
#

Then yeah, put the variables in the URL structure and you're good

fervent vapor
#

i did it

fervent vapor
slate swan
eager bough
#

Hi everyone

#

How are yall puto's (:

foggy zealot
#
import discord
import asyncio
from discord.ext import commands
from pythonping import ping

bot = commands.Bot(command_prefix='>')
client = discord.Client()

class Client(discord.Client):
    async def on_ready(self):
        print('Logged on as {0}!'.format(self.user))

    async def on_message(self, message):
        print('Message from {0.author}: {0.content}'.format(message))

async def my_background_task():
    await client.wait_until_ready()
    while not client.is_closed():
        response_list2 = ping('35.158.5.187', size=40, count=10)
        ms2 = int(response_list2.rtt_avg_ms)
        response_list = ping('168.119.193.207', size=40, count=10)
        ms = int(response_list.rtt_avg_ms)

        if ms > 0 and ms <= 33:
            desc = '🟒 Online'
        elif ms > 33 and ms < 66:
            desc = '🟑 Minor Outage'
        elif ms >= 66:
            desc = '🟠 Serious Outage'
        else:
            desc = 'πŸ”΄ Offline'

        if ms2 > 0 and ms2 <= 33:
            desc = '🟒 Online'
        elif ms2 > 33 and ms2 < 66:
            desc = '🟑 Minor Outage'
        elif ms2 >= 66:
            desc = '🟠 Serious Outage'
        else:
            desc = 'πŸ”΄ Offline'
        message = await client.get_channel(968499225845432330).fetch_message(968499691446755379)
        await message.edit(embed=discord.Embed(title="Statuses", description=(f"**Node-01**: {desc} -  [`{ms}ms`]\n**Database**: {desc} - [`{ms2}ms`]"), color=0x1eff00))
        embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/912797781888999438/964829134553493534/Comp_1.gif")
        embed.set_footer(text="Updates every 5 seconds")
        await ctx.send(embed=embed)
        await asyncio.sleep(5)
bg_task = client.loop.create_task(my_background_task())

client.run('token')

why ms dont update?

eager bough
#

OMFG we answered this alr

foggy zealot
#

when

eager bough
#

Everyone don't answer him

#

we alr told him

#

how to do it so many times

foggy zealot
#

the answer isnt: " dont know how to use this module"

eager bough
#

read the docs

#

don't ask here

velvet compass
#

That doesn't seem like a helpful response

eager bough
foggy zealot
#

-.-

eager bough
#

scroll up

#

@velvet compass

velvet compass
#

Then it should be easy to say "Have you tried what I mentioned earlier?" Instead of "Everyone don't help him, don't ask here, read the docs"

fervent vapor
#

how would i only let poeple type commands in a channel

eager bough
fervent vapor
#

but if its a message

eager bough
#

so like wdym

fervent vapor
#

how would i delete

eager bough
#

how to purge messages?

fervent vapor
#

so in 1 channel, you can type a command, but not a message

eager bough
#

im confused

#

can u be more spacific

#

i got to leave here in 3m

fervent vapor
#

that is specific, you can only type discord commands in a channel, not random messages such as "asdnhjasbdjhasbadj"

eager bough
#

correct

fervent vapor
#

!invite

eager bough
#

ok

fervent vapor
#

i ahve it workingbut i can type random things in the channel, i dont want that

eager bough
#
@client.command(name='invite')
async def invite(ctx):
#

@fervent vapor

fervent vapor
#

yes thgat works

eager bough
#

you can finish the rest of the code with embeds or ctx.send

fervent vapor
#
async def invite(ctx):```
eager bough
#

yh

fervent vapor
#

see? but how do i stop something that is not "!invite"

eager bough
#

on_command_erroro

fervent vapor
#

oh my goodness

eager bough
#

im need to go

fervent vapor
#

i need someone else

eager bough
#

ok ...

fervent vapor
#

cya

eager bough
#

cya

slate swan
#

Do you have the channel ID?

fervent vapor
#

yes

#

i just dmed u lol, but u have friends off

fervent vapor
slate swan
#

There are different ways to do that

fervent vapor
#

what is the easiest

slate swan
#

One would be to implement a custom check and the other one would be to simply make a check in your code.
The easy way would be something like

async def ...(ctx, ...):
    if ctx.channel.id != <id>:
        return
    # The command code here
#

It will basically stop the code from executing if the channel ID is not the one given

fervent vapor
#

no i understand that

#

please dont leave cuz i rlly wanna finish this today

#

I have x channel, lets call it "#bot-commands", now if someone says "hello" in the channel it would get deleted,
but if someone says "!invite" it would run the command

#

basically i only want commands run in there, and if its not a command i want it dleted

fervent vapor
slate swan
#

Technically you can make the bot delete every message in the channel, if it was a valid command it will get executed

fervent vapor
#

yes and i tried that, but it doesnt let the command work then

slate swan
#

Otherwise you'd need to check if the message sent in that channel is a valid command using the on_message event

fervent vapor
#
async def on_message(message):
  if message.channel.id == 968596034060156938 or message.channel.id == 968476806141329478:
    await message.channel.purge(limit=1)```
slate swan
fervent vapor
#

this is what i have

slate swan
#

Yeah - you're missing await client.process_commands(message)

fervent vapor
#

where do i put that?

slate swan
#

Not sure about that but you probably need to use the function and then delete the message

#

So right before your purge

#

You could technically just do await message.delete()

fervent vapor
#

now it works

#

but it also deletes the bot's message

slate swan
#

Yeah, add a check at the top of the event that ignores bots

#

!d discord.Member.bot

unkempt canyonBOT
#

property bot```
Equivalent to [`User.bot`](https://discordpy.readthedocs.io/en/master/api.html#discord.User.bot "discord.User.bot")
slate swan
#

This returns True if the member is a bot

#

message.author would be your discord.Member object

#

If the bot attribute is True then you can return

fervent vapor
#

if message.author != User.bot:

#

like that or no

#

sorry i legit started python today lol

slate swan
#

You can just do

if message.author.bot:
    print("User is a bot")
fervent vapor
#

for some reason it still deletes the bot message

slate swan
#

I highly recommend learning more Python before jumping in making a Discord bot wolfWriting

fervent vapor
#

``

#
async def on_message(message):
  await client.process_commands(message)
  if message.author.bot:
    return
  else:
    if message.channel.id == 968596034060156938 or message.channel.id == 968476806141329478:
      await message.channel.purge(limit=1)```
slate swan
#

The else is not needed

fervent vapor
#

well i know python, i just mean that i just got back to it, i shouldve said again

#

but it still deletes the bot's messages

#

bro idk why it wont just do it

slate swan
#

You sure you've run the updated version of the file?

fervent vapor
#

yes

#
async def on_message(message):
  await client.process_commands(message)
  if message.author.bot:
    return
  if message.channel.id == 968596034060156938 or message.channel.id == 968476806141329478:
    await message.channel.purge(limit=1)```
#

this is it now

#

still no luck

slate swan
#

Put the bot check at first

#

You also don't want to execute commands if it is coming from a bot

fervent vapor
#

just did that still deletes it

#
async def on_message(message):
  if message.author.bot:
    return
  if message.channel.id == 968596034060156938 or message.channel.id == 968476806141329478:
    await client.process_commands(message)
    await message.channel.purge(limit=1)```
slate swan
#

What if you add a print to debug right before deleting the message?

fervent vapor
#

i just did that

#

trying rn

#

wth

#

it prints it before the return

#

idk man

slate swan
#

What if you put as check

if ​message​.​author​ ​==​ ​bot​.​user​ ​or​ ​message​.​author​.​bot​:
    return
fervent vapor
#

do i need to import something?

slate swan
#

Nope

#

Interesting because it works in my code

#

Like, that is my code which ignores bot users

 
 ​@​bot​.​event 
 ​async​ ​def​ ​on_message​(​message​: ​disnake​.​Message​) ​->​ ​None​: 
 ​    ​""" 
 ​    TheΒ codeΒ inΒ thisΒ eventΒ isΒ executedΒ everyΒ timeΒ someoneΒ sendsΒ aΒ message,Β withΒ orΒ withoutΒ theΒ prefix 
 ​    :paramΒ message:Β TheΒ messageΒ thatΒ wasΒ sent. 
 ​    """ 
 ​    ​if​ ​message​.​author​ ​==​ ​bot​.​user​ ​or​ ​message​.​author​.​bot​: 
 ​        ​return 
 ​    ​await​ ​bot​.​process_commands​(​message​)
fervent vapor
#

"bot.user or message.author.bot:" this shows up as an error

slate swan
#

Yeah you probably need to type it manually

#

There seem to be some issues with the GitHub app which gives weird characters when I'm copying

fervent vapor
#

omg

#

im gonna kms

#
async def on_message(message):
  if message.author == client.user or message.author.bot:
    print("Hi")
    return
  if message.channel.id == 968596034060156938 or message.channel.id == 968476806141329478:
    await client.process_commands(message)
    await message.channel.purge(limit=1)```
#

still no

slate swan
#

If you print before .purge()

fervent vapor
#

it prints both "Hi" and "test"

#
async def on_message(message):
  if message.author == client.user or message.author.bot:
    print("Hi")
    return
  if message.channel.id == 968596034060156938 or message.channel.id == 968476806141329478:
    await client.process_commands(message)
    print("test")
    await message.channel.purge(limit=1)```
slate swan
#

Wait, both?

fervent vapor
#

yes

slate swan
#

Oh yeah, once for your message and once for the bot's message I guess

fervent vapor
#

oh that would make sense

#

but it prints test second which makes no sense

slate swan
#

Doesn't really make sense honestly or I'm tired and can't see what's wrong

#

What if you print message.author.bot and message.author at the top

fervent vapor
#

ill try

#

wtf

#

it all checks out

slate swan
#

Okay so

#

Don't use .purge

#

Use await message.delete()

fervent vapor
#

omg

#

i just realised

slate swan
#

Then make sure you don't delete a message somewhere else, just in case

fervent vapor
#

i had message.channel.purge()

#

it works now

#

not message.purge()

#

tysm for the help

slate swan
fervent vapor
#

TYSM

silver agate
#

AttributeError: 'Bot' object has no attribute 'slash_command'. Did you mean: 'add_command'?

tf is this?

slate swan
#

Library?

silver agate
#

jishaku

silver agate
fervent vapor
#

do u know a fix?

slate swan
#

It tries to delete an already deleted message

fervent vapor
#

why tho?

slate swan
silver agate
#

what should I use then for that code :

fervent vapor
#

do you know how i can fix it @slate swan

silver agate
#
bot = commands.Bot(
    command_prefix= commands.when_mentioned,
    intents= discord.Intents.default()
)

@bot.slash_command(guild_ids=[961585785226821703])
async def hello(ctx):
    await ctx.respond(f"Hello {ctx.author}!")

@bot.slash_command(
    name="hi"
)
async def global_command(ctx, num: int):
    await ctx.respond(f"This is a global command, {num}!")```
slate swan
fervent vapor
#
async def on_message(message):
  await client.process_commands(message)
  if message.author.bot:
    return
  if message.channel.id == 968596034060156938 or message.channel.id == 968476806141329478:
    await message.delete()
    return```
#

i added return at the end to see if it would fix it

slate swan
#

Do you delete the message in the command you use?

fervent vapor
#

yes

#

i will change that now

slate swan
#

Then don't delete it

fervent vapor
#

tysm love you @slate swan

tacit token
#

Hi guys, how can i make this with my code?

    @commands.Cog.listener()
    async def on_member_update(self, before, after):
        if before.roles != after.roles:
                roles = [role for role in after.roles[1:]]
                channel = self.bot.get_channel(server_config[after.guild.id]['server_log'])
                embed = discord.Embed(title="Role updates")
                embed.add_field(name="Before",value="".join([role.mention + "|" for role in before.roles[1:]]))
                embed.add_field(name="After",value="".join([role.mention + "|" for role in after.roles[1:]]))
                await channel.send(embed=embed)
silver agate
#

thats not a command

slate swan
#

And if you want commands to be executed only in those channels put back the process_commands back in the if statement

silver agate
slate swan
#

Please read the entire conversation before saying that

tacit token
#

so i need just the "added" or the "removed" role

slate swan
#

Get the difference between the two lists

#

Then you know which role got added/removed

#

Check which role got added/removed from the after.roles list

tacit token
tacit token
slate swan
#

For example you could use list(set(x)-set(y)), which will give which role has been removed.

#

Or you can get the difference by XORing both sets which will give both directly - might be "complex" if you don't know XOR

#

Easy method would be the first one

#

!e
a = [1, 2, 3]
b = [1, 2]
print(list(set(a)-set(b)))

unkempt canyonBOT
#

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

[3]
slate swan
#

Here the 3 got removed

#

Then you know how to invert it and make it the opposite, check if something got removed from a

tacit token
#

so i need len the roles, and set the len-1?

slate swan
#

To know if it got removed/added?

#

You can just use a simple if list(set(a)-set(b)): statement for example. Then an element from a got removed

#

!e
a = [1, 2, 3]
b = [1, 2]
c = [1, 2, 3, 4]
if list(set(a)-set(b)):
print("Removed")

You can check yourself which element has been added to c compared to a

unkempt canyonBOT
#

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

Removed
tacit token
#

and i how to import this to a code?

#

sorry it's midnight here and i need to sleep: D thanks

#

gn

slate swan
#

after.roles and before.roles would be your lists (a and b for example)

vast flame
#

Is anyone familiar with Nextcord and got a minute to look over something for me to see where I am being thick?

slate swan
#

Don't ask to ask, just ask :) If someone can help they will do

vast flame
#

TLDR is this: I am trying to pass a list of options through to a function within a class. The list flagList is generated within the command and is needed within a decorator of the function (Line 6) to populate the dropdown. Not very familiar with classes and can't figure out if what I am trying is possible and then how to go about it if it is.

Code is here: https://paste.nextcord.dev/?id=1651007066361787

ornate aspen
#

Btw, do you guys perform caching in an another worker or do you just do it along with the bot?

royal jasper
#

how can i convert a timestamp like that? 1611516336000

#

yes, but look at the year

#

and i want to convert it from a string

#

like: day: {day}, year: {year}

slate swan
#

Question:
Is there a way to monitor the server count with a image? Like the picture?
If yes, how?

#

Yes, store the server count somewhere every X time, usually a database, and then make a diagram using a library - matplotlib might help

eager bough
#

i am backi am back

#

i am back

slate swan
royal jasper
slate swan
#

Just get rid of the last 3 numbers (000) which are for timestamp with milliseconds. Discord doesn't like them :)

#

So use 1611516336 instead of 1611516336000

royal jasper
slate swan
exotic maple
#

Does anyone know how to fix this error?

await em.add_reaction("\U00002705") TypeError: object NoneType can't be used in 'await' expression

#

Anyone?

eager bough
#

.

eager bough
exotic maple
#

no lol

#

ive tried that

eager bough
#

send code

exotic maple
#

await ctx.send(embed=em)
emoji = ["\U00002705"]
await ctx.add_reaction(emoji)

fervent vapor
#

is anyone familiar with replit or no

eager bough
fervent vapor
#

do u know how to keep a bot active 24/7

eager bough
torn sail
unkempt canyonBOT
#
Out of the question.

No documentation found for the requested symbol.

eager bough
#

...

fervent vapor
eager bough
exotic maple
eager bough
exotic maple
#

Im not sending my whole code as you dont need it

eager bough
#

and not readable

exotic maple
#

await ctx.send(embed=em) emoji = ["\U00002705"] await ctx.add_reaction(emoji)

#

its readable...

eager bough
#

no not rly lol

exotic maple
#

...

eager bough
exotic maple
#

Yes, do you?

eager bough
exotic maple
#

bro why r u testing me, do u know how to help me or not

eager bough
exotic maple
#

or im just going to find someone who can actually fix problems

#

its readable bro

eager bough
#

It legit not readable

exotic maple
#

It is 🀣 , you just dont know how to fix it

eager bough
#

u send embed after the embed code lol

exotic maple
#

I have the embed code but i dont need to show you it

eager bough
exotic maple
torn sail
#

How is that helpful

eager bough
#

i rlly cant help u bc it is not readable

#

ask someone else

exotic maple
#

No you just don't know it

eager bough
exotic maple
#

What do you mean? I remember you got muted before 🀣

#

Now let me find a real discord.py programmer that can help me, bye

eager bough
exotic maple
#

You're not a mod

eager bough
#

No but i am inforcing the rules

torn sail
#

And I looked at ur GitHub account…

eager bough
exotic maple
#

🀣 , this guy doesnt know anything i swear

eager bough
torn sail
exotic maple
#

He makes an excuse that he can't read my basic code

#

Because he can't fix it

torn sail
#

His code looks much worse honestly

#

Let’s just stop please

eager bough
exotic maple
eager bough
torn sail
eager bough
#

oh yh i have not used that in a long time

idle laurel
#

how can i start/call a background task which is located in a different file through a command?

eager bough
torn sail
eager bough
exotic maple
#

Now leave me alone

torn sail
#

Ok can we all stop please

exotic maple
eager bough
exotic maple
eager bough
torn sail
#

Just calm down

#

Don’t respond

eager bough
#

<@&831776746206265384> @exotic maple

eager bough
exotic maple
#

Stop pinging me

#

I'm busy

eager bough
#

Ok, i hope u find help somewhere else

hollow badger
#

What's up?

eager bough
exotic maple
idle laurel
exotic maple
#

@hollow badger

torn sail
# hollow badger What's up?

So @exotic maple asked for help and then @eager bough kept saying that β€œit’s not readable no will will help you” then said to be on topic and also wants the other guy to prove he knows discord.py

exotic maple
#

Yep.

eager bough
#

yh

#

accept

#

y delete message?

idle laurel
#

just seems to be here to troll rather than help

eager bough
#

if u want ur bot to be online

idle laurel
exotic maple
#

Not help, i thought that is what this server is for

eager bough
#

Nope. Not rlly lol

torn sail
#

β€œFree hosting” has many down sides

idle laurel
#

heroku free dyno does the trick

hollow badger
#

While paying for hosting is indeed an option, you could have avoided coming across as flippant if you explained as such. Also, telling other people their code is bad and demanding they prove their knowledge is also not conducive to a welcoming and respectful environment.

If you don't want to be constructive or helpful, I suggest you don't say anything.

@eager bough

eager bough
#

Oky sounds good

#

thanks!

idle laurel
exotic maple
#

Alright thanks, ill try it out

idle laurel
#

how can i start/call a background task which is located in a different file through a command?

eager bough
#

for example

idle laurel
#

ive imported from the class in my file, but when i call blahblah.task_name.start(args) it returns AttributeError: 'coroutine' object has no attribute 'start'

eager bough
#

run maybe?

torn sail
idle laurel
#

.start() works fine when i start the task in the main folder

eager bough
#

please don't message me

mortal dove
#

Is there an event for on_slash_command in discord.py? on_command doesn't pick them up.

idle laurel
eager bough
torn sail
#

Don’t tell people what lib to use if they already have picked one

mortal dove
#

I looked for an event listener, not a lib. Thanks.

torn sail
eager bough
idle laurel
torn sail
#

If not then asyncio.create_task

#

!d asyncio.create_task

unkempt canyonBOT
#

asyncio.create_task(coro, *, name=None)```
Wrap the *coro* [coroutine](https://docs.python.org/3/library/asyncio-task.html#coroutine) into a [`Task`](https://docs.python.org/3/library/asyncio-task.html#asyncio.Task "asyncio.Task") and schedule its execution. Return the Task object.

If *name* is not `None`, it is set as the name of the task using [`Task.set_name()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.Task.set_name "asyncio.Task.set_name").

The task is executed in the loop returned by [`get_running_loop()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_running_loop "asyncio.get_running_loop"), [`RuntimeError`](https://docs.python.org/3/library/exceptions.html#RuntimeError "RuntimeError") is raised if there is no running loop in current thread.

This function has been **added in Python 3.7**. Prior to Python 3.7, the low-level [`asyncio.ensure_future()`](https://docs.python.org/3/library/asyncio-future.html#asyncio.ensure_future "asyncio.ensure_future") function can be used instead...
idle laurel
daring olive
#

you're on your last warning @eager bough

torn sail
#

!d discord.on_interaction

unkempt canyonBOT
#

discord.on_interaction(interaction)```
Called when an interaction happened.

This currently happens due to slash command invocations or components being used...
torn sail
#

And check if the interaction has a command

#

!d discord.Interaction.command

unkempt canyonBOT
#

The command being called from this interaction.

If the interaction is not an application command related interaction or the command is not found in the client’s attached tree then None is returned.

torn sail
#

@mortal dove

mortal dove
#

Ohh thank you!

final iron
daring olive
flat solstice
#

any particular reason I should use datetime.datetime.now instead of datetime.datetime.utcnowin my embed timestamps, in converts to the users local time anyway right?

eager bough
#

hi

#

yh i think so

#

try this.

@client.command(name='clear')
@commands.has_permissions(administrator=True)
async def (ctx, nombre: int):
  await ctx.delete(limit = nombre)
#

Np bro

#

wait lol

#

i messed up

#
@client.command()
@commands.has_permissions(administrator=True)
async def clear(ctx, amount: int):
  await ctx.channel.purge(limit = amount)
#

@slate swan

#

np

#

oh