#discord-bots

1 messages Β· Page 993 of 1

slate swan
#

__init__.py

#

ah it looks like it because of the version dunder but youre right it wouldnt have so much imports lol

#

just dont run its src!

#

i do!

#

^

#

running what

formal basin
#

How can I make it so no prefix you say the command

olive osprey
#

πŸ’€

slate swan
#

its not as said hes accessing the file which ofc it would raise an error since its a relative import it doesn't know the parent package

slate swan
formal basin
slate swan
#

and if you're not planning to use prefix

#

just use commands.when_mentioned or None(if it works, i'm not sure 'bout this one)

pliant gulch
#

Just set the prefix to ""

#

This allowing all messages to be triggered

slate swan
#

andy what is that nickname

pliant gulch
#

It’s a void pointer

#

I couldn’t find a null pointer so I had to make do

slate swan
pliant gulch
#

It’s kind of like a wildcard pointer

#

It’s a pointer with no specific type

#

So it can really be casted to any type

slate swan
#

mhm

#

nice

dull terrace
#

What is this new app discovery thing for discord? Is it going to make places like top.gg defunct?

sick birch
#

Set timeout=None and also bot.add_view() because views "timeout" when a bot goes offline

#

I say "timeout" in quotes because it doesn't really timeout, your bot just can't recognize them after it restarts

#

So using add_view makes it persistent

slate swan
#

just guessing tho lol

olive osprey
#

Hi, I got a small problem, the bot isn't sending the error message for some reason.

  
    @commands.command(aliases=["ei", "ej", "einfo"])
    @commands.bot_has_permissions(embed_links=True)

The permission is called embed_links isn't it?

    @emojiinfo.error
    async def emojiinfo_error(self, ctx, error):
      if isinstance(error, commands.BotMissingPermissions):
        eeembed = discord.Embed(title="Error has been issued!", description=f"`{error}`\n*Looks like the bot is missing some permissions.*", color=discord.Colour.dark_red())
        eeembed.set_footer(text="commands.BotMissingPermissions")
        await ctx.reply(embed=eeembed)
dull terrace
slate swan
#

like.. most of the ppl don't really use "explore public server" discovery thingy

#

they just google "official discord server of xyz or whatever"

#

... so... let's see :")

dull terrace
dull terrace
#

same model as top.gg uses with ads to get your server or bot seen

slate swan
frozen patio
slate swan
#

well it's kinda like playstore, but of discord bots

dull terrace
#

discord.bot is wrong

olive osprey
dull terrace
#

not sure what it's supposed to be but if you do print(str(dir(discord))) you'll get all possible attributes

slate swan
#

!d discord.ext.commands.has_permissions

unkempt canyonBOT
#

@discord.ext.commands.has_permissions(**perms)```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that is added that checks if the member has all of the permissions necessary.

Note that this check operates on the current channel permissions, not the guild wide permissions.

The permissions passed in must be exactly like the properties shown under [`discord.Permissions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions "discord.Permissions").

This check raises a special exception, [`MissingPermissions`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingPermissions "discord.ext.commands.MissingPermissions") that is inherited from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").
slate swan
#

@dull terrace

olive osprey
#

just saw it, that's the permission for the member

slate swan
#

yep

dull terrace
slate swan
dull terrace
#

oh okay okay

frozen patio
#

Yea, you do not need bot in @commands.has_permissions line

slate swan
#

bro

frozen patio
#

I do not think at least

olive osprey
#

discord.ext.commands.bot_has_permissions(**perms)
Similar to has_permissions() except checks if the bot itself has the permissions listed.

This check raises a special exception, BotMissingPermissions that is inherited from CheckFailure.

dull terrace
slate swan
#

TYPOS

#

it's gonna be same as how we treat server discovery thing

#

!d discord.ext.commands.bot_has_permissions

unkempt canyonBOT
#

@discord.ext.commands.bot_has_permissions(**perms)```
Similar to [`has_permissions()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.has_permissions "discord.ext.commands.has_permissions") except checks if the bot itself has the permissions listed.

This check raises a special exception, [`BotMissingPermissions`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.BotMissingPermissions "discord.ext.commands.BotMissingPermissions") that is inherited from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").
dull terrace
#

i didn't even know server discovery existed till like 2 weeks ago

slate swan
#

πŸ˜…

frozen patio
#

Oh

#

LMAO

#

I did not know that existed πŸ‘€

olive osprey
#
      if isinstance(error, commands.BotMissingPermissions):

Well, then why doesn't it throw the error?

slate swan
#

@olive osprey type hint error to CommandError

olive osprey
#

will trythumbs_up

slate swan
#

idk if the converter converts the type but idk i see nothing else wrong

olive osprey
slate swan
olive osprey
#

Yeah for some reason it throws invalid syntax

slate swan
#

show

olive osprey
slate swan
#

in your functions parameters!

olive osprey
#

oh

#

πŸ’€

full lily
#

that colon should be a comma

slate swan
#

he typehinted in the wrong place lol

full lily
#

why are we type hinting??

slate swan
#

because i see no issue with his code (review it i probably missed something) and idk if the converter converts the type

tiny ibex
#

how do i delete a msg?

olive osprey
#

Tried it with

    async def emojiinfo_error(self, ctx, error: CommandError):

&

    async def emojiinfo_error(self, ctx, error: commands.CommandError):

First one throws syntax error, and second one does the same error as before

slate swan
unkempt canyonBOT
#

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

Deletes the message.

Your own messages could be deleted without any proper permissions. However to delete other people’s messages, you need the [`manage_messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_messages "discord.Permissions.manage_messages") permission.

Changed in version 1.1: Added the new `delay` keyword-only parameter.
tiny ibex
slate swan
#

a message?

olive osprey
#

lmao

#

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

tiny ibex
slate swan
#

i mean yes the method does return a message obj

tiny ibex
#
eru jsk py
_bot.get_message(967101932776865832).delete()```
full lily
slate swan
olive osprey
tiny ibex
slate swan
#

bro

tiny ibex
#

NVM I missed a bracket

#
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.9/site-packages/jishaku/features/python.py", line 149, in jsk_python
    async for send, result in AsyncSender(executor):
  File "/app/.heroku/python/lib/python3.9/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File "/app/.heroku/python/lib/python3.9/site-packages/jishaku/repl/compilation.py", line 140, in traverse
    async for send, result in AsyncSender(func(*self.args)):
  File "/app/.heroku/python/lib/python3.9/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File "<repl>", line 1, in _repl_coroutine
    _bot.get_message(967101932776865832).delete()
AttributeError: 'NoneType' object has no attribute 'delete'```
#

But now this

tiny ibex
#

It should be in bot's cache

slate swan
#

if the message isnt in cache it would return None

vale wing
#

Discord be like

slate swan
#

smh

olive osprey
#

@slate swan what would happen if i use except discord.Forbidden shouldn'T that work?

olive osprey
tiny ibex
#
eru jsk py
message = await _bot.fetch_message(967101932776865832)
message.delete()```
slate swan
#

ah nice show

olive osprey
tiny ibex
#
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.9/site-packages/jishaku/features/python.py", line 149, in jsk_python
    async for send, result in AsyncSender(executor):
  File "/app/.heroku/python/lib/python3.9/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File "/app/.heroku/python/lib/python3.9/site-packages/jishaku/repl/compilation.py", line 140, in traverse
    async for send, result in AsyncSender(func(*self.args)):
  File "/app/.heroku/python/lib/python3.9/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File "<repl>", line 1, in _repl_coroutine
    message = await _bot.fetch_message(967101932776865832)
AttributeError: 'Bot' object has no attribute 'fetch_message'```
tiny ibex
#

WTF!

olive osprey
# olive osprey

But for some reason it just doesn't send the error message

tiny ibex
#

it can't even fetch the message

slate swan
tiny ibex
#

wut

olive osprey
#

How do you expect me to do that?

#

what

tiny ibex
#

??

olive osprey
#

I don't know for the other ones, but I got a problem sending an error message

tiny ibex
#

how to do it??

#

then what to do??

slate swan
#

i swear it did

tiny ibex
#

How may I ask you?

slate swan
#

How could i get the message that an interaction is on when the interaction is interacted with

tiny ibex
#

BRUHH

slate swan
#

wait

unkempt canyonBOT
#

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

Creating a Bot account is a pretty straightforward process.

tiny ibex
#

wtf

#

-_-

slate swan
tiny ibex
#

there is textchannel

#

!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.
tiny ibex
#

I will fetch it from channel

tiny ibex
#
eru jsk py
channel = _bot.get_channel(943187319064785008)
message = await channel.fetch_message(967147456892641310)
message.delete()```It doesn't delete yet!!
tiny ibex
#

it doesn't raise any error

olive osprey
#

huh?

slate swan
#

Yeah I figured that out myself πŸ’€

tiny ibex
slate swan
#

I am a bit stupid

#

it raises the error but for some reason it doesnt catch it

olive osprey
#

^

slate swan
#

How could I delete that message?

#

interaction.message.delete doesn’t do anything

tiny ibex
#

thnx man

olive osprey
slate swan
#

Oh with the curly brackets

olive osprey
#

lmO

#

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

I think I tried it once already, let me try again

#

Yeah same thing

#

Sure, where do you want me to put it? Into the error handler?

#
      if isinstance(error, commands.errors.BotMissingPermissions)

Doesn't work

austere vale
#
  @commands.Cog.listener()
  async def on_member_join(self,member:nextcord.Member):
      await member.add_roles(933983900609441812)

is there anything wrong with my code? my bot isnt adding the autorole

olive osprey
#

wrong command

olive osprey
unkempt canyonBOT
#

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

Gives the member a number of [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s.

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 added [`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.
olive osprey
#

What do you mean exactly? The type is "discord.ext.commands.errors.BotMissingPermissions"

slate swan
#

im loving metaclasses

olive osprey
#

Is there any chance that I need to import error/s from discord.ext

#

well that's pretty much my code lol

austere vale
#

tysm!!

slate swan
#

theyre pog

olive osprey
#

Does an emojiinfo command invoke any CommandInvokeError?

royal jasper
#

how can i get role by name in a client.wait_for?

slate swan
#

!e

def lol():
    print(a)
    a = 1
lol()
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 lol
004 | UnboundLocalError: local variable 'a' referenced before assignment
flint isle
#

How can I get a list of the messages in a channel

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...
olive osprey
#

Is there any error handler for "discord.errors.Forbidden"?

olive osprey
#

lemme try something

#

bruh @heavy igloo @slate swan i think i found the error

slate swan
#

what is it

olive osprey
#

Well, I was experimenting and thought that people could take the perms away for embed links from my bot yk, and well, how is my bot supposed to send an error in an embed without embed perms?

slate swan
#

πŸ’€

olive osprey
slate swan
#

this chat is confusing me allot

olive osprey
#

lmfao i can't this fr was the problem KEKW

slate swan
#

!d discord.Permissions.embed_links

unkempt canyonBOT
olive osprey
#

yeah everything works as expected now lmfao

slate swan
#

i hate dpys abstractions

olive osprey
#

Man idk, it almost destroyed my brain so I'm happy to see it work now

#

Yeah, thanks to you both for trying to help, appreciate it

slate swan
#

πŸ’œ

unkempt canyonBOT
#

@dense swallow Per Rule 6, your invite link has been removed. If you believe this was a mistake, please let staff know!

Our server rules can be found here: https://pythondiscord.com/pages/rules

dense swallow
#

oops

#

hi im trying to make acknowledgements in userinfo cmd
code: ```py
async def get_acknowledgements(self, member):
bot_guild = self.bot.get_guild(764049436275114004)
staff_role = bot_guild.get_role(849669358316683284)

    if member.id == self.bot.owner_id:
        return [f":owner: Owner of {self.bot.user.name}"]

    if staff_role in member.roles:
        return [f":staff: Staff member in the [support server](link)"]

this in ui cmd

    acks_list = await self.get_acknowledgements(member)
    acks = "\n".join(acks_list)

errorpy
['Traceback (most recent call last):\n', ' File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 181, in wrapped\n ret = await coro(*args, **kwargs)\n', ' File "D:\Projects\PizzaHat\PizzaHat\cogs\utility.py", line 63, in userinfo\n acks = "\n".join(acks_list)\n', 'TypeError: can only join an iterable\n', '\nThe above exception was the direct cause of the following exception:\n\n', 'Traceback (most recent call last):\n', ' File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 360, in invoke\n await ctx.command.invoke(ctx)\n', ' File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 927, in invoke\n await injected(*ctx.args, **ctx.kwargs)\n', ' File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 190, in wrapped\n raise CommandInvokeError(exc) from exc\n', 'discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: can only join an iterable\n']

dense swallow
plucky lodge
#

whatever, well thats not at all how you do it on dpy

#

you gotta make a command tree

#

then use @tree.command (for slash commands)

#

yes

#

but you gotta define tree as an instance of CommandTree

fleet sparrow
#

hello, i have a question
how i can check if a user have a role in a message event?
i try doing

    if role in message.author.roles:

but isnt working is giving me this error AttributeError: 'User' object has no attribute 'roles'

pliant gulch
royal jasper
#

for the name of the role. and then the bot gets the role by name and add to the user

pliant gulch
flat solstice
#

anyway I could make this workpy if "COMMUNITY" in before.features or "COMMUNITY" in after.features.community: print( 'Checking "COMMUNITY" in before.features or "COMMUNITY" in after.features.community' ) elif ( "COMMUNITY" not in before.features or "COMMUNITY" not in after.features.community ): print( 'Checking "COMMUNITY" not in before.features or "COMMUNITY" not in after.features.community' )in a way that doesn't produce this errorpy Ignoring exception in on_guild_update Traceback (most recent call last): File "C:\Users\Teagan\Documents\Coding\Zupie\env\lib\site-packages\discord\client.py", line 375, in _run_event await coro(*args, **kwargs) File "C:\Users\Teagan\Documents\Coding\Zupie\bot\cogs\events.py", line 101, in on_guild_update if "COMMUNITY" in before.features or "COMMUNITY" in after.features.community: AttributeError: 'list' object has no attribute 'community'since the code I want to run only needs to run if a guild is a community server

fleet sparrow
#

πŸ™ƒ

magic ore
#

because it doesn't exist; removing that should fix your code

flat solstice
magic ore
flat solstice
#

oh

flat solstice
rapid jetty
#

Guys how do I make my bot configured to work on multiple servers with json?

sick iris
#

so i want to make a queing systme with a json file does anyone know how i could like append stuff to the json file

#

and then how can a read from it and get 1 single object from it

hollow agate
#

Let's say I have memberchannel = client.get_channel(932124870173683782) defined within a command, which works fine, but it's quite messy. Is there a way that I can make a global definition to work everywhere so I don't have to keep defining that variable in every single command?

slate swan
#

        with open("logs.stonks","r") as f:
            logschannel = f.read()
        print(logschannel)
        channel2 = self.bot.get_channel(logschannel)
        embed=discord.Embed(color=0xFF0000)
        embed.set_author(name=f"{member} ({memberID}) has STARTED a request", icon_url=pfp)
        embed.timestamp = datetime.datetime.utcnow()
        await channel2.send(f"{membermention}",embed=embed)

and then logs.stonks has 940354454983704668 in it, which is the channel id

#

how come it doesn't work?

slate swan
#

at what point

torn sail
#

get_channel takes int

#

logschannel = int(f.read())

mortal dove
#

And anyone help me with discord.py views? I'm trying to just make a base view class, and then I can add different selects. This is the code:
https://mystb.in/AnaRefreshProcesses
The error I receive is Hybrid command raised an error: Command 'help' raised an exception: AttributeError: 'CogSelect' object has no attribute '_row'
The way I call it is view = HelpMenu().add_item(CogSelect(self.bot))
Any help is appreciated!

slate swan
#

thank you

#

appreciate it @torn sail

torn sail
#

πŸ‘

torn sail
mortal dove
#

Oh hang on I just looked at the message you sent

fervent shoal
#

intents = Intents.default()
intents.members = True
class logger(commands.Cog):
def init(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(message):
print('logger module online')

mortal dove
#

That shouldn't be a return, it should be a continue BRUH

fervent shoal
#

is there something wrong in this>

mortal dove
#

please use ```py ``` btw

fervent shoal
#

oh my bad

#
intents.members = True
class logger(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
    @commands.Cog.listener()
    async def on_message(message):
        print('logger module online')```
mortal dove
#

the listener should take self as well as message, because it's in a class

#

also not sure why you're redefining intents in a cog

fervent shoal
#

says message is not accsessed anymoe

#

yike tf happened there

mortal dove
#

That's ok

#

It's just saying you are not using the message parameter

#

it will still run perfectly okay πŸ‘

fervent shoal
#

its not working

mortal dove
#

send code

fervent shoal
#

one sec, i found this code of the internet so it probably has a lot of errors left

unkempt canyonBOT
#

Hey @fervent shoal!

You either uploaded a .txt file or entered a message that was too long. Please use our paste bin instead.

mortal dove
#

Don't copy code from the internet my g

fervent shoal
#

i did it for some shits and giggles with my friendfs

mortal dove
#

You don't learn anything and you don't know how it works so it's impossible to debug

fervent shoal
#

yea true

mortal dove
#

idk what that's even supposed to do but I see it everywhere

#

Are you trying to get logging?

fervent shoal
#

@mortal dove how would i go about making something like GenAi, stuff that takes in what other people in the server are saying and uses words and says it

#

like if a bunch of people said "hello" over and over, the bot would take that in and say that

mortal dove
#

That's way over your head, but if you wanna do that then you should probably ask questions in #data-science-and-ml and implement what you find into python code

fervent shoal
#

ah

#

do you know how to take in information at least?

mortal dove
#

like from messages?

fervent shoal
#

yes

mortal dove
#

That's just

@commands.Cog.lister()
async def on_message(self, message: discord.Message):
  # append it to a .txt or .log file or something
dull terrace
#

froggy_chill should i add reaction gifs to my bot like owobot has

#

it would be pretty easy and i could do it better

fervent shoal
#

sorry if im being really stupid rn

flat solstice
#

so I'm using a on_guild_update event and only want this guild name field to appear if the name gets chnaged but atm it's showing all the timepy if before.name is not after.name: embed.add_field(name="Name", value=f"{before.name} -> {after.name}")

mortal dove
fervent shoal
#

i fixed it, had to google that one

unkempt canyonBOT
#
is

6.10.3. Identity comparisons

The operators is and is not test for an object’s identity: x is y is true if and only if x and y are the same object. An Object’s identity is determined using the id() function. x is not y yields the inverse truth value. 4

slate swan
#

should use !=

flat solstice
#

ah okay

fervent shoal
#

why am i getting this problem, its just happened, and how do i fix it

mortal dove
#

Send codeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

#

e

fervent shoal
#
    def __init__(self, bot):
        self.bot = bot
        self._last_member = None

class logger(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
    @commands.Cog.listener()
    async def on_message(self, message):
        print('logger module online')

class MyClass(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_message(self, message: discord.Message):
            print(message)

def setup(bot: commands.Cog):
    bot.add_cog(MyClass(bot))


bot.run(TOKEN)```
fervent shoal
mortal dove
#

the whole thing

slate swan
#

bro his error is in run

fervent shoal
#

that is the whole thing, i scrapped the internet one

slate swan
#

you should learn oop before using cogs

mortal dove
#

That's the whole file?

fervent shoal
#

maybe im the error

mortal dove
#

mayhaps

#

I would recommend getting more familiar with python before making a bot. I actually admire your ambition but, bluntly, making bots is hard. You're welcome to try, but it seems like this is one of the first projects you have done.

fervent shoal
#

ive done another one

#

it was a few months back tho

#

that one worked perfectly fine

mortal dove
#

You've made another bot?

fervent shoal
#

yea

#

that one works just fine

#

but that aside, once i fix the bot issue will the code take in all words said in a channel with the code i have in rn or not

mortal dove
#

Well, you're asking for help with some of the most basic errors in python (ie syntax and undefined variables)

mortal dove
fervent shoal
#

its not showing anything in terminal

#

and the bots online as well

flat solstice
# slate swan should use `!=`

all right new question, I have this if statement currently configured to add the field if either before.afk_channel or after.afk_channel exist, is there a way I can adapt this so it keeps the current functionality but also only adds the field if before.afk_channel and after.afk_channel are different?py async def channel_check(self, before, after): return f"{getattr(before, 'mention', None)} -> {getattr(after, 'mention', None)}" if before.afk_channel or after.afk_channel: embed.add_field( name="Afk channel", value=await channel_check(self, before.afk_channel, after.afk_channel), )

rapid jetty
#

Guys, does someone knows how do I make my bot configured to work on multiple servers with json?

fervent shoal
#
    def __init__(self, bot):
        self.bot = bot
    @commands.Cog.listener()
    async def on_message(self, message):
        print('logger module online')

class MyClass(commands.Cog):

    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_message(self, message: discord.Message):
        await print(message)

def setup(bot: commands.Cog):
    bot.add_cog(MyClass(bot))


bot.run(TOKEN)```

not printing anything at all
flat solstice
fervent shoal
#

logger do be not defined

flat solstice
#

Are those classes in the same file

echo wasp
#

Ignoring exception in on_member_remove
Traceback (most recent call last):
File "/home/maskuhpq/.local/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
TypeError: on_member_remove() takes 1 positional argument but 2 were given

echo wasp
# echo wasp Ignoring exception in on_member_remove Traceback (most recent call last): File...
    @commands.Cog.listener()
    async def on_member_join(self):
        guild = self.client.get_guild(8048640127684977438)
        channel = self.client.get_channel(966846673380556900)
        await channel.edit(name=f"{len(guild.members)} Members")

    @commands.Cog.listener()
    async def on_member_remove(self):
        guild = self.client.get_guild(8048640127684977438)
        channel = self.client.get_channel(966846673380556900)
        await channel.edit(name=f"{len(guild.members)} Members")```
slate swan
#

anyone know why this doesn't mention the channel ( #discord-bots for example )
await ctx.channel.send(f"Admin speak and response channel changed to: <#{channel2}>")

but this does?
await ctx.channel.send(f"Admin speak and response channel changed to: <967189798517342248>")

and any fixes?

wicked atlas
#

!d discord.on_member_join

unkempt canyonBOT
#

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

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

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

ik i fixed it before you got back to me

wicked atlas
#

Nice

wicked atlas
#

And what does it send in the message?

slate swan
# wicked atlas What is stored in `channel2`?

'''py

with open("speak.stonks","r") as f:
newchannel = int(f.read())
f.close()
channel2 = self.bot.get_channel(newchannel)
await ctx.channel.send(f"Admin speak and response channel changed to: <#{channel2}>")'''

#

on mobile so formatting isn't working

#

channel2 has the channel id inside

sick birch
#

channel2 needs to either contain an ID or a discord.TextChannel instance

slate swan
#

it has the id

wicked atlas
#

get_channel returns a channel object, which when converted to a string will print the channel's name, not the id. You can use channel.mention to mention it

f"{channel2.mention}"
sick birch
#

Doesn't look like it

#

It has holup

slate swan
#

thats the channel name

sick birch
#

Yeah, it needs to have an ID not the channel name

slate swan
#

it has the id...

#

it turns the id into the name

sick birch
#

Then why does it say holup?

wicked atlas
#

!d discord.abc.GuildChannel.mention

unkempt canyonBOT
sick birch
#

Doesn't look like it since you're just concatenating it using f strings

slate swan
#

???

#

wdym it doesn't look like it

#

can clearly see it is in that ss lol

sick birch
#
 await ctx.channel.send(f"Admin speak and response channel changed to: <#{channel2}>")
#

This doesn't convert it to an ID from the name

slate swan
#

im entering an id and its changing to the name

sick birch
#

Ah, well keep it as an ID then

sick birch
#

Don't convert it to a name

slate swan
#

'''py

with open("speak.stonks","r") as f:
newchannel = int(f.read())
f.close()
channel2 = self.bot.get_channel(newchannel)
await ctx.channel.send(f"Admin speak and response channel changed to: <#{channel2}>")'''

#

the whole point is I want it to mention the channel

sick birch
#

Looks like you have the discord.TextChannel object, so just do channel2.mention

slate swan
#

ok ill try that

rare saddle
#

Please tell me how to download all the images that are in the channel? With the help of a bot

sick birch
#

That's going to be difficult and take a long time

rare saddle
echo wasp
#

how do i put that in an f string with text around it?

sick birch
sick birch
#

Yeah. If you can get it into a variable, you can get it into an f string

umbral night
#
@bot.event
async def on_member_join(member):
  channel=bot.get_channel(944112299151618128)
  await channel.send(f'{member.mention}, welc to saudi\n{member.guild.member_count}')

why doesn't this work?

#

it doesn't send anything

#

and there arent any errors

mortal dove
#

For slash commands and hybrid commands in discord.py, is there any way to describe an argument? Something like

async def command(
  self, 
  ctx: Context, 
  arg: Option(name="name", description="A name or something", _type=str) = "Nothing"
):
desert halo
#

bunch of guys discussed about it 2-3 days ago

little viper
#
Traceback (most recent call last):
  File "C:\Users\mp420\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 352, in _run_event    
    await coro(*args, **kwargs)
  File "C:\Users\mp420\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 793, in on_connect       
    await self.register_commands()
  File "C:\Users\mp420\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 338, in register_commands
    to_update = update_guild_commands[guild_id]
KeyError: '951383974817697793'``` how do i fix? guild id is correct, I am sure of that
sick birch
daring olive
#

what's a 'hybrid command'?

echo wasp
#

@sick birch didn't work

little viper
desert halo
#

message command with app command

sick birch
desert halo
#

at the same time

little viper
sick birch
#

Huh?

#

It's your code isn't it?

sick birch
echo wasp
# sick birch Oops. You haven't to `list()` it
@commands.command(name="update", description="Updates the member count!")
    async def update(self, ctx):
        guild = self.client.get_guild(8048546012184977438)
        hannel = self.client.get_channel(967194657531402862)
        annel = self.client.get_channel(9671966866644967535)
        channel = self.client.get_channel(9668466745380556900)
        bot_user = filter(lambda x: x.bot, guild.members)
        user = filter(lambda x: not x.bot, guild.members)
        await channel.edit(name=f"{len(guild.members)} Total Members")
        await hannel.edit(name=f"{user} Humans")
        await annel.edit(name=f"{bot_user} bots")
        await ctx.send("Member count has been updated!")```
sick birch
#

Also be aware you can only change channel name twice every 10 minutes

#

So it's probably better that you run a @tasks.loop with a 5 minute interval

sick birch
#

With making a tasks loop?

echo wasp
little viper
umbral night
#
@bot.event
async def on_member_join(member):
  channel=bot.get_channel(944112299151618128)
  await channel.send(f'{member.mention}, welc to saudi\n{member.guild.member_count}')

why doesnt this work?

unkempt canyonBOT
#

Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default, discord.py has all intents enabled, except for the Members and Presences intents, which are needed for events such as on_member and to get members' statuses.

To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.

Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

intents = Intents.default()
intents.members = True

bot = commands.Bot(command_prefix="!", intents=intents)

For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.

supple thorn
#

Do you have member intents on

umbral night
#

yes

supple thorn
umbral night
#

yes

#

wait no

supple thorn
sage otter
sick birch
#

Yeah that works too

sage otter
#

f"There are {len([i for i in guild.members if not i.bot])} humans in the server"

supple thorn
sick birch
#

I personally prefer filter but yeah

umbral night
supple thorn
#

If the print statement doesn't work then your event isn't getting triggered

little viper
#
Traceback (most recent call last):
  File "C:\Users\mp420\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 352, in _run_event    
    await coro(*args, **kwargs)
  File "C:\Users\mp420\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 793, in on_connect       
    await self.register_commands()
  File "C:\Users\mp420\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 338, in register_commands
    to_update = update_guild_commands[guild_id]
KeyError: '951383974817697793'```
umbral night
little viper
brisk dune
little viper
#
    to_update = update_guild_commands[guild_id]
KeyError: '951383974817697793'
``` from here
brisk dune
#

That's the error

#

What caused the error? The actual code you were executing

little viper
#

i mean theres a lot but okay

#
        async for guild in self.fetch_guilds(limit=None):
            update_guild_commands[guild.id] = []
        for command in [
            cmd
            for cmd in self.pending_application_commands
            if cmd.guild_ids is not None
        ]:
            as_dict = command.to_dict()
            for guild_id in command.guild_ids:
                to_update = update_guild_commands[guild_id]
                update_guild_commands[guild_id] = to_update + [as_dict]

        for guild_id, guild_data in update_guild_commands.items():
            try:
                commands = await self.http.bulk_upsert_guild_commands(
                    self.user.id, guild_id, update_guild_commands[guild_id]
                )```
vale estuary
#
        args = message.content.split(' ')
        if len(args) == 2:
            member: Member = discord.utils.find(lambda m: args[1] in m.name, message.guild.members)
            if member:
                await member.ban()
                await message.channel.send(f'Member {member.name} gebannt.')
            else:
                await message.channel.send(f'Kein User mit dem Namen {args[1]} gefunden.')```

**DOES SOME1 KNOW WHY MY BAN NOT WORKING?**
supple thorn
supple thorn
#

Lmao you're manually finding the member

dusky pine
vale estuary
brittle bear
#

how do i load cogs in dpy 2.0?

#

i heard they made it async

dusky pine
supple thorn
brittle bear
#

im not on the pypi version

supple thorn
slate swan
#

(BETTER THAN YOUTUBE)

vale estuary
#

what should i write instead

supple thorn
#

Yeah visit vcokltfre's website

supple thorn
#

!d discord.ext.commands.Bot

unkempt canyonBOT
#

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

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

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

Unlike [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client"), This class does not require manually setting a [`CommandTree`](https://discordpy.readthedocs.io/en/master/interactions/api.html#discord.app_commands.CommandTree "discord.app_commands.CommandTree") and is automatically set upon instantiating the class.
slate swan
vale estuary
#

thx

dusky pine
#

wonder if it's possible to make discord bot that can make me literally fly irl

slate swan
#

We can

#

Through flights ✈

echo wasp
#

@sick birch Traceback (most recent call last):
File "/home/maskuhpq/.local/lib/python3.9/site-packages/discord/ext/tasks/init.py", line 101, in _loop
await self.coro(*args, **kwargs)
TypeError: stats() missing 1 required positional argument: 'member'

#

it works great when not on a loop

supple thorn
echo wasp
#
   @tasks.loop(minutes=5)
    async def stats(self, member: discord.member):
        guild = self.client.get_guild(80486467782184977438)
        hannel = self.client.get_channel(967167619731402862)
        annel = self.client.get_channel(967196586546644967535)
        channel = self.client.get_channel(96686765473380556900)
        bot_user = len(list(filter(lambda x: x.bot, guild.members)))
        user = len(list(filter(lambda x: not x.bot, guild.members)))
        await channel.edit(name=f"{len(guild.members)} Total Members")
        await hannel.edit(name=f"{user} Humans")
        await annel.edit(name=f"{bot_user} bots")```
#

(note ids not vaild)

sick birch
#

ah loops don't take a member argument

echo wasp
sick birch
#

hm?

echo wasp
# sick birch hm?

nhandled exception in internal background task 'stats'.
Traceback (most recent call last):
File "/home/maskuhpq/.local/lib/python3.9/site-packages/discord/ext/tasks/init.py", line 101, in _loop
await self.coro(*args, **kwargs)
TypeError: stats() missing 1 required positional argument: 'member'
I'm in as Bro's SMP Bot#7548!
^CTask exception was never retrieved
future: <Task finished name='Task-1' coro=<Loop._loop() done, defined at /home/maskuhpq/.local/lib/python3.9/site-packages/discord/ext/tasks/init.py:88> exception=TypeError("stats() missing 1 required positional argument: 'member'")>
Traceback (most recent call last):
File "/home/maskuhpq/.local/lib/python3.9/site-packages/discord/ext/tasks/init.py", line 125, in _loop
raise exc
File "/home/maskuhpq/.local/lib/python3.9/site-packages/discord/ext/tasks/init.py", line 101, in _loop
await self.coro(*args, **kwargs)
TypeError: stats() missing 1 required positional argument: 'member'

supple thorn
slate swan
#

Ye

echo wasp
slate swan
#

Imagine ticket booking in discord

echo wasp
#

@sick birch

sick birch
#

my bad I was eating

#

And you got this error after removing member: discord.Member?

sick birch
#

That's odd. Can I see code?

echo wasp
#

i sent you code!

sick birch
#

That was before you removed member

echo wasp
# sick birch That was before you removed member
@tasks.loop(minutes=5)
    async def stats(self):
        guild = self.client.get_guild(80486467782184977438)
        hannel = self.client.get_channel(967167619731402862)
        annel = self.client.get_channel(967196586546644967535)
        channel = self.client.get_channel(96686765473380556900)
        bot_user = len(list(filter(lambda x: x.bot, guild.members)))
        user = len(list(filter(lambda x: not x.bot, guild.members)))
        await channel.edit(name=f"{len(guild.members)} Total Members")
        await hannel.edit(name=f"{user} Humans")
        await annel.edit(name=f"{bot_user} bots")```
sick birch
#

Okay that parts right

#

Did you save?

echo wasp
#

yes

sick birch
#

Did you forget to remove your other command?

echo wasp
#

nope

sick birch
#

This is the only function named "stats"?

echo wasp
sick birch
#

That's strange

#

Either there's some other function named stats or it's not saved

rapid jetty
#

Guys how do I make my bot configured to work on multiple servers with json?

sick birch
#

I'm not sure what else it might be

echo wasp
sick birch
#

I did, but the error makes sense if you hadn't saved your code

#

That or there's another function called stats

#

How are you starting the loop?

echo wasp
#

self.stats.cancel()
self.stats.start()

sick birch
#

That's right

#

Yeah, I'm stumped. That's very strange

echo wasp
#

can you try it?

#

on your own bot

prime marten
#

hi, im currently using sqlite3 and am having some troubles with this join, it displays the member_id twice in the output. Can anyone help?

heavy folio
prime marten
#

oh, this does concern my discord bot but thanks anyways

echo wasp
royal oar
#

Would anyone know how to have a like event where if someone is put into timeout it starts an event
Like
on_membet_ban at all? I am trying to make a logging event where if a member is put into timeout it would activate

boreal ravine
#

Triple fail

slate swan
#

im so tired

#

πŸ˜”

hushed galleon
#

lol

slate swan
#

im going to sleepπŸ˜”

hushed galleon
sick birch
echo wasp
sick birch
#

What do you mean?

boreal ravine
heavy folio
#

ah

dapper tapir
#

how can i make the bot take a transcript of the channel and send it to a sepertate channel for logs

echo wasp
sick birch
#

Don't have anyone like that unfortunately

echo wasp
#

okmi?

sick birch
slate swan
dapper tapir
#

i mean, it put its into a file

sick birch
#

Ah

echo wasp
sick birch
#

Yeah, alright, that's fine

echo wasp
#

scrooll up for code and error codes

dapper tapir
#

you know what i mean or you need a example?

sick birch
#

I know what you mean, don't worry

#

Same principle, loop through, write content of message to file

dapper tapir
#

do you know what i need to do?

slate swan
dapper tapir
#

i dont know how to do that?

sick birch
#

Probably might want to store it in some sort of buffer

sick birch
dapper tapir
hushed galleon
slate swan
sick birch
hushed galleon
#
print('hello')
self.stats.start()``` then make sure hello shows up before the error message
supple thorn
dapper tapir
#

thats not really much help sorry

dapper tapir
#

could i send you what ive got and you take a look?

slate swan
sick birch
#

I'm guessing you want more help on actually writing to file instead of getting the messages?

dapper tapir
#

yeah

sick birch
#

And also examples

unkempt canyonBOT
#

Hey @dapper tapir!

It looks like you tried to attach file type(s) that we do not allow (.html). We currently allow the following file types: .gif, .jpg, .jpeg, .mov, .mp4, .mpg, .png, .mp3, .wav, .ogg, .webm, .webp, .flac, .m4a, .csv, .json.

Feel free to ask in #community-meta if you think this is a mistake.

dapper tapir
#

could you accept my friend req please

sick birch
#

!paste I don't do dms, sorry. Use this for your code

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.

hushed galleon
#

if you only need to upload the transcript and not actually save it to your drive, then i would suggest an in-memory file like io.StringIO

dapper tapir
sick birch
#

yeah good point, i'm guessing you'll just be sending that to another channel

dapper tapir
#

that i cant send here

sick birch
#

what file?

dapper tapir
#

a webm

#

html even

sick birch
#

why do you need to send HTML?

#

we just need to see your code

dapper tapir
#
import discord
from discord.ext import commands

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)
        self
    async def on_message(self, message):
        # don't respond to ourselves
        if message.author == self.user:
            return

        if "ip" in message.content:
          await message.reply('``connect 61:28035``',mention_author=True)

        if "hack" in message.content:
         await message.reply('Please do not call out cheaters. Make a ticket here [#952679827046006804](/guild/267624335836053506/channel/952679827046006804/)', mention_author=True)
         await message.delete()
    
        if "esp" in message.content:
         await message.reply('Please do not call out cheaters. Make a ticket here [#952679827046006804](/guild/267624335836053506/channel/952679827046006804/)', mention_author=True)
         await message.delete()

        if "giveaway" in message.content:
         await message.reply('If you have recieved a dm about a giveaway it is a scam. Make a ticket here [#952679827046006804](/guild/267624335836053506/channel/952679827046006804/)', mention_author=True)

        if "cheater" in message.content:
         await message.reply('Please do not call out cheater. Make a ticket here [#952679827046006804](/guild/267624335836053506/channel/952679827046006804/)', mention_author=True)
         await message.delete()

        if "aimbot" in message.content:
         await message.reply('Please do not call out cheaters. Make a ticket here [#952679827046006804](/guild/267624335836053506/channel/952679827046006804/)', mention_author=True)
         await message.delete()

        if "help" in message.content:
          await message.reply('Please create a ticket in via out support system, [#952679827046006804](/guild/267624335836053506/channel/952679827046006804/) ',mention_author=True)
          await message.delete()

        if message.content == '?1':
         await message.channel.send('Hey there, thanks for contacting support today. What is it that we can help you with today?')
         await message.delete()

        if message.content == '?upload':
         await message.channel.send('Hey there, for us to be able to process your report we need to have evidence of the person that your reporting, please could you upload your clip.\nIf your clip is too large to upload to discord please upload it to https://streamable.com/ and then send the link here.\nMany thanks Swift Rust.')
         await message.delete()

        if message.content == '?close':
         await message.channel.send('Hello thank you for opening a ticket today, we hope that we met your needs and please rate your experience with us.\nIf you have any more support needs please feel free to make another ticket.\nThis ticket will be closed in 5 minutes, so if you have any final questions please do now.\nMany thanks from the Swift Rust staff team.')
         await message.delete()

client = MyClient()
client.run('')```
echo wasp
#

what the heck

dapper tapir
#

but what im trying to currently is set up a system that will put all the messages into a file like this

echo wasp
#

that is not how you do commands

heavy folio
#

aws is so confusing god

sick birch
heavy folio
dapper tapir
echo wasp
dapper tapir
#

and thats a html file

sick birch
#

@dapper tapir this could really benifit from a dictionary

heavy folio
dapper tapir
#

wdym?

sick birch
#

Could be. Again, I only used the non-education version so I wouldn't know haha

echo wasp
heavy folio
#

ah

dapper tapir
sick birch
#

Loop through that, check if message.contents has any of that

#

if so just do stuff["key"] and send that

#

instead of massive if chains that frankly are hard to read and understand

dapper tapir
#

and what do i put in the "something" part?

heavy folio
#

something would be your message

dapper tapir
#

right okay

#

thanks

heavy folio
#

that's a dictionary and it has key-value pairs
{"key": "value"}

dapper tapir
#
        if message.contents:
        stuff = {
          "ip": "Please do not call out cheaters. Make a ticket here [#952679827046006804](/guild/267624335836053506/channel/952679827046006804/)"
          "hack" ....```
#

like this?

#

wait im just getting distracted atm

#

i need to know how to do that transcript thing

sick birch
#

Use in memory files like was suggested

rare saddle
#

How to make the bot not delete messages two weeks ago? (ping me, please)

slate swan
#

Hey

#

!rule 9

unkempt canyonBOT
#

9. Do not offer or ask for paid work of any kind.

slate swan
#

Yikes

dapper tapir
#

how can i make so its just like

#

i dont have to do this for every filtered word

sick birch
#

do what

granite plume
#

hey

#

i installed the discord module

dapper tapir
#
        if "fa**ot" in message.content:
          await message.delete

        if "n***er" in message.content:
         await message .delete```
granite plume
#

but it can't seem to get recognized

dapper tapir
granite plume
sick birch
#

Have a list of them

granite plume
dapper tapir
sick birch
#
bad_words = ["bad word #1", "bad word #2", "bad word #3", ...]
for bad_word in bad_words:
  # check if message has a bad word, delete if so
granite plume
dapper tapir
#

but you see how i done it

sick birch
#

Bad word filters are pretty hard to implement perfectly considering how many workarounds there are

granite plume
#
[word for word in bad_words if word in message.content]

or something like that idk

sick birch
#

using levenshtein distance is a bit better

granite plume
#

anyways

#

discord's not being imported for some reason

dapper tapir
#
        if "n54","461" in message.content:
          await message.delete```
#

is it possible to do it like this?

sick birch
#

Unfortunately no

#

You an also do set difference if you wanted to

dapper tapir
sick birch
#

Just follow the blueprint I gave you

#

You'd probably want that inside an on_message listener

dapper tapir
#

would this work?

sick birch
#

No

#

You need to actually check if the message has that word in it

dapper tapir
quaint epoch
#

!pypi better_profanity

unkempt canyonBOT
sick birch
#

That should go inside the for loop

sick birch
supple thorn
quaint epoch
#

i don't know who recommended that but no

supple thorn
quaint epoch
#

uses any()

supple thorn
#

I'm asking why would they use a list comprehension for this

regal pulsar
regal pulsar
#

yeah use that

quaint epoch
#

any(i in message.content for i in list_of_swears)

#

would return true if a swear is detected

#

but ofc there are libs which do it much better

slate swan
#

imagine using a library for just this much

regal pulsar
#

lmao

quaint epoch
slate swan
quaint epoch
slate swan
#

huh?

#

use regex uwu

quaint epoch
#

just use a lib smh

regal pulsar
slate swan
#

ikr

slate swan
regal pulsar
regal pulsar
quaint epoch
#

why does everyone in this channel use regex?

#

i'll let hunter sort this out

slate swan
#

i'll just stop saying controversial things, things sorted

regal pulsar
#

i mean

#

one guy told me that message.startswith() in on_message() was better than bot.command() and a prefix

slate swan
regal pulsar
slate swan
#

πŸ’€ oh gawd wtf

slate swan
#

sheesh just make slash commands

#

^ +1

regal pulsar
#

cant find the startswith thing

supple thorn
regal pulsar
#

but he changed it to this when i asked him to fix it

slate swan
# regal pulsar

πŸ™‚ bro... just wanna say, that it's not a good practice

regal pulsar
supple thorn
slate swan
#

bro, don't mind.. one of his friend must have said it.. let it be like that.. :'/ let's help him now..

regal pulsar
slate swan
#

lmaoo

#

OHH SSHEEESHHH

regal pulsar
#

i wasnt lying

slate swan
#

MESSI + RONALDO = MESSIALDO

regal pulsar
#

smh

supple thorn
regal pulsar
slate swan
#

pls

#

dont

supple thorn
slate swan
#

well whatever

regal pulsar
slate swan
#

ok jk nvm

maiden fable
slate swan
#

fr lmao

#

Can we not backbite some innocent random person?

#

innocent, yes

supple thorn
#

Innocent

supple thorn
maiden fable
supple thorn
#

\πŸ‘€

regal pulsar
#

talk about stubborn

slate swan
#

LMAO feature?

slate swan
supple thorn
#

Where he is

regal pulsar
slate swan
#

lmaoo u going to his house? cokecake

supple thorn
regal pulsar
slate swan
#

...

supple thorn
regal pulsar
#

who said it was a window

supple thorn
#

I can't open up his dms

regal pulsar
#

check under your bed

regal pulsar
supple thorn
slate swan
regal pulsar
#

then check pending

slate swan
#

!ot ahem ahem

unkempt canyonBOT
slate swan
#

ahem ahem

regal pulsar
supple thorn
regal pulsar
#

i sent him your user

#

why is friending people such a big deal

#

its not like they're actually your friends now

#

its just so they can send you a message

maiden fable
#

I just like it how y'all are making him accept Skev's friend when he can just join the server solve the issue and leave the server

slate swan
#

why even join the server lmao, just help with his code :"/

regal pulsar
#

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

maiden fable
#

Bru

zenith mural
#

o

slate swan
maiden fable
#

Hi

slate swan
#

ooo he's here

supple thorn
#

@zenith mural your code make us cry at night

maiden fable
#

There

zenith mural
#

ok

regal pulsar
#

i guess it could be some creep

supple thorn
slate swan
regal pulsar
#

but that would probably be more fun

zenith mural
supple thorn
maiden fable
#

Take the to an ot @regal pulsar @slate swan

regal pulsar
supple thorn
#

!d discord.ext.commands.Bot

zenith mural
#

o

unkempt canyonBOT
#

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

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

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

Unlike [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client"), This class does not require manually setting a [`CommandTree`](https://discordpy.readthedocs.io/en/master/interactions/api.html#discord.app_commands.CommandTree "discord.app_commands.CommandTree") and is automatically set upon instantiating the class.
slate swan
supple thorn
#

This has commands

regal pulsar
supple thorn
#

Use them

slate swan
regal pulsar
#

lmao

#

also

slate swan
supple thorn
regal pulsar
#

ctx.channel.send() >> > ctx.send()

maiden fable
#

BTW did everyone get this message from discord

supple thorn
#

But we couldn't think of shit

slate swan
maiden fable
regal pulsar
supple thorn
#

So i went to python general

maiden fable
#

Too long to copy paste

slate swan
supple thorn
maiden fable
#

Mhm

#

Prolly cz of that

slate swan
#

yeah pretty sure only owners of verified bots

maiden fable
#

Prolly cz those are the ones who are getting affected the most

slate swan
regal pulsar
regal pulsar
supple thorn
regal pulsar
#

but .channel.send is still better

slate swan
supple thorn
slate swan
maiden fable
#

Yea

slate swan
#

πŸ’€my man prefers to write long code, he's koder

maiden fable
#

ctx.send also looks clean

supple thorn
#

Yeah

#

You just got yourself jumped by 4 people

slate swan
#

LMAO

supple thorn
#

Answer

regal pulsar
#

this looks way better

supple thorn
regal pulsar
#

does 🐲

slate swan
#

I prefer swwet and simple, so ctx.send is one for me :>

supple thorn
#

Ctx.send looks better

slate swan
regal pulsar
#

yeah

slate swan
#

why do you write it like that

regal pulsar
#

but i wont get vsc's syntax highlighting otherwise

slate swan
#

.... bruh

supple thorn
regal pulsar
supple thorn
#

And not the return type

regal pulsar
#

see

slate swan
#

bruh just use dark+ syntax

#

open the extensions tab and download it

supple thorn
slate swan
#

it doesn't make any difference anyway

supple thorn
#

Blue and yellow looks old like a old ass piece of paper that turned yellow

slate swan
#

it's actually better for it to be grey

#

the methods pop out compared to the fn name

regal pulsar
slate swan
#

whatever

regal pulsar
#

the green is the best imo

supple thorn
slate swan
#

πŸ’€ ppl started color theory wtf

#

we're not in art class

regal pulsar
supple thorn
#

If it isn't

slate swan
#

πŸ˜‚

supple thorn
#

Why

slate swan
#

thats enough ducky

regal pulsar
#

hmm

slate swan
#

oh my fucking god

supple thorn
#

Wtf

slate swan
#

im not

#

holy shit im not even

regal pulsar
supple thorn
#

Nyx boutta fold your ass

regal pulsar
#

gets people every time

slate swan
#

jesus christ who was cruxified for our sins

#

WHAT THE FUCK

regal pulsar
#

lmfao

slate swan
#

IS THAT.

#

OS.SYSTEM FOR GIT COMMANDS???

supple thorn
#

Bite em nyx, bite em

slate swan
#

LMAOOO

#

im just out of words bro

#

how is that even useful

regal pulsar
supple thorn
slate swan
#

are you that lazy that you can't just win + r > cmd > enter

slate swan
supple thorn
#

I'm gonna go and think about rocks

slate swan
#

go and touch some grass too, if possible :")

supple thorn
#

Only smoke

slate swan
#

....

regal pulsar
#
try:
    print("Hello World")
except:
    pass
paper sluice
#

..

slate swan
regal pulsar
#

its very nice isnt it

slate swan
#

yes :")

regal pulsar
#

my best work

gaunt ice
#

hm

#

hello guys

slate swan
#

hello xeno :>

gaunt ice
#

C=

regal pulsar
#

hey

slate swan
regal pulsar
#

oh yeah

slate swan
#

:")

sick birch
regal pulsar
regal pulsar
#

🐲

sick birch
#

yes very

regal pulsar
#

how could you πŸ˜”

#

i require an apology

slate swan
#

ohhh no

regal pulsar
#

true python

slate swan
sick birch
#

Bit off topic don't you think

slate swan
#

shipit i just realised that there's a Library named uvloop ( which may be common to use, im learning about it late) that can speedup asyncio event loops

#

but sadly, it doesn't work for windows

spring flax
#

so I have ```py
@cache(ttl=10)
async def gun_names():
async with bot.db.execute("SELECT gun FROM builds") as cursor:
data = await cursor.fetchall()
return [gun_name[0] for gun_name in data]

def needed_autocomplete(choices: typing.Callable[[], typing.List[str]], n: int = 10):
async def actual(inter, option: str):
rev = await choices
if option in rev:
return option
matches = fuzzy_match(option, choices, n=n)
return list(matches)
return actual

@bot.slash_command()
async def build(
inter: disnake.CommandInteraction,
mode : listmode,
gun: str = commands.Param(autocomplete=needed_autocomplete(gun_names)),

#

and it raises ``` rev = await choices
TypeError: object function can't be used in 'await' expression

hot cobalt
#

You've forgotten to call choices to return a coroutine

#

await choices()

spring flax
#

wait let me try something else

buoyant zodiac
#

what is passed in the on_guild_channel_create ??

spring flax
#

!d discord.on_guild_channel_create

unkempt canyonBOT
#

discord.on_guild_channel_delete(channel)``````py

discord.on_guild_channel_create(channel)```
Called whenever a guild channel is deleted or created.

Note that you can get the guild from [`guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.GuildChannel.guild "discord.abc.GuildChannel.guild").

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

!d discord.on_guild_channel_update it takes two parameters

unkempt canyonBOT
#

discord.on_guild_channel_update(before, after)```
Called whenever a guild channel is updated. e.g. changed name, topic, permissions.

This requires [`Intents.guilds`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.guilds "discord.Intents.guilds") to be enabled.
slate swan
#
async def on_guild_channel_update(before, after):
  ...
#

uh....

#

sheesh, why would that happen, try re-running

#

what's onii?

#

....what

slate swan
#

onii is not defined

#

you want to fetch it

#

ah sorry mb

#

you could just update the table no?

#

onii = onii + 1

gaunt ice
#

sql confusion

slate swan
#
@client.command()
async def select(ctx):
    await ctx.send(
        "select Menu",
        components = [
            Select(
                placeholder = "Select something!",
                options = [
                    SelectOption(label = "69", value = "420"),
                    SelectOption(label = ":)", value = ":(")
                ]
            )
        ]
    )

    interaction = await client.wait_for("select_option")
    await interaction.send(content = f" selected!")

this is my code and the select menu is sent by the bot but upon clicking a option it says interaction failed
no errors shown in console

static lintel
#

i seem to have an issue where my button doesn't edit my message. this is the line of code that's supposed to edit it but it doesn't seem to do anything when i click on the button. Any idea on what i did wrong?

        await interaction.response.edit_message(content=client.crypto_pages[current+1])```
wise kettle
static lintel
wise kettle
# static lintel is this correct?

yeah looks right. not sure why it's not working in that case. have you confirmed that the button_callback() function is getting invoked?

gaunt ice
wise kettle
#

well, a print statement should work

static lintel
gaunt ice
#

the last one

static lintel
gaunt ice
#

what is the error

slate swan
#

Why doesn't it trigger the error handler when I call the class using raise MaximumValuesReached()

elif isinstance(error, MaximumValuesReached):
  await inter.edit_original_message("You have reached the maximum number of notes!")

The error class


class MaximumValuesReached(Error):
    def __init__(self):
        super().__init__("maximum values reached")
torn sail
#

You can access the original error with this

#

!d discord.ext.commands.CommandInvokeError.original

unkempt canyonBOT
slate swan
slate swan
#
    @role.group(pass_context=True)
    async def delete(self, ctx, role: str):
        role = discord.utils.get(ctx.guild.roles, name=role)
        if role not in ctx.guild.roles:
            await ctx.send(f"there is no role named **{role}**")
        else:
            discord.utils.get(ctx.guild.roles, name=role)
            await role.delete()
            await ctx.send(f"role **{role}** has been deleted πŸ‘")

this give me None type back when i try to delete a role that doesnt exist

feral lichen
#

how could one make it so if you do like !role member :emoji: it gives the member the role

slate swan
#

try:
await role.delete()
except:
await ctx.send("role not found")

#

or, if role != ctx.guild.roles
@slate swan

slate swan
#

show me the code

#

sec

slate swan
slate swan
#

show me the code

#

this was the first one

#

    @role.group()
    async def delete(self, ctx, role: str):
        role = discord.utils.get(ctx.guild.roles, name=role)
        try:
            discord.utils.get(ctx.guild.roles, name=role)
            await role.delete()
            await ctx.send(f"role **{role}** has been deleted πŸ‘")
        except:
            if role not in ctx.guild.roles:
                await ctx.send(f"there is no role named **{role}**")
boreal ravine
slate swan
#

but that one also give me the None type when i try to delete it

#

Yo back from school

slate swan
slate swan
# slate swan ```py @role.group() async def delete(self, ctx, role: str): rol...
    @role.group()
    async def delete(self, ctx, role: str):
        role = discord.utils.get(ctx.guild.roles, name=role)
        try:
            discord.utils.get(ctx.guild.roles, name=role)
            await role.delete()
            await ctx.send(f"role **{role}** has been deleted πŸ‘")
        except:
            if role != ctx.guild.roles:
                await ctx.send(f"there is no role named **{role}**")

number 2

#
    @role.group(pass_context=True)
    async def delete(self, ctx, role: str):
        role = discord.utils.get(ctx.guild.roles, name=role)
        if role != ctx.guild.roles:
            await ctx.send(f"there is no role named **{role}**")
        else:
            discord.utils.get(ctx.guild.roles, name=role)
            await role.delete()
            await ctx.send(f"role **{role}** has been deleted πŸ‘")
#

Wrong emoji

slate swan
slate swan
#

append the rolename to a var then

#

then send the var

#

i mean

#

i already tried doing role: discord.Role

#

also dont work, cus thats what other people said

feral lichen
#

i got big question```py
@bot.command()
async def role(ctx, member: discord.Member, *, arg):
emoji = bot.get_emoji(967297501961015327)
if arg.content == emoji:
await member.add_roles(discord.utils.get(ctx.guild.roles, name="buyer"))

slate swan
#

why dont you just typehint role to discord.Role?

slate swan
#

Yeah

#

yes

#

tried that

#

nvm

#

that wont even send the message

#

listen

#

that does nothing

slate swan
#

ctx,*,role

feral lichen
slate swan
#

role:discord.Role

#

try this remove str from role and add a asterisk before the argument

slate swan
#

!d discord.Role

unkempt canyonBOT
#

class discord.Role```
Represents a Discord role in a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild")...
slate swan
#

he is trying to get the role name to be sent in the message

feral lichen
slate swan
#

did you guys even check the code