#discord-bots

1 messages · Page 509 of 1

rugged tinsel
#

embed

viral prawn
#

Ik embed but how do I make the bot capture role info

#

like how many people has the role?

#

and a matplotlib

rugged tinsel
#

idk

tough wagon
visual island
#

use walrus operator

#

actually, i dont think it will work with generator expression

slate swan
#
    @commands.Cog.listner()
    async def on_message(self,message):
        if message.author.bot:
            return
        if any(str(bot.get_user(user_id)) for user_id in message.content.split() if user_id.isdigit()):
            uid = await self.coll.find_one({"user_id": str(user_id), "reaction" str(reaction)}) #getting the user ID if in db then getting reaction
            await message.add_reaction(reaction)

Would something like that work?

ocean leaf
#

how can i make this type of timestamp in dpy?

viral prawn
#

@skqwid#7560 is here too.

ocean leaf
paper bane
#

You can by setting the timestamp attribute of embeds to a datetime object

green jacinth
#

ok thx like can u help me with it

#

nvm i did it thx

slate swan
green jacinth
#

k

ocean leaf
paper bane
#

yes, that'd be a valid datetime object

ocean leaf
paper bane
#

any valid datetime object will work

#

doesn't just have to be a UTC one

ocean leaf
#

ok

#

i ama make a new py file and try using dstetime

#

this is what utcnow returns

#

not much readable

slate swan
paper bane
#

set it as the timestamp attribute and discord will parse it

#

embed.timestamp = datetime.datetime.utcnow()

ocean leaf
#

embed.set_timestamp(datetime.datetime.utcnow()) ?

slate swan
#

or you can have py timestamp = in discord.Embed itself

boreal ravine
#

aren't u supposed to tell us?

rugged tinsel
#

just take a photo

ocean leaf
#

yeah it works

#

thanks

boreal ravine
#

Send it..

#

just copy paste

ocean leaf
boreal ravine
#

the error..?

unkempt canyonBOT
#

set_footer(*, text=Embed.Empty, icon_url=Embed.Empty)```
Sets the footer for the embed content.

This function returns the class instance to allow for fluent-style chaining.
boreal ravine
#

copy paste the error here

ocean leaf
boreal ravine
#

!paste or this

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.

boreal ravine
#

KeyError
If you get a KeyError, it means what you are looking for isn’t in the dict/json. There are many solutions for this:

  1. Make a try-except to make a default value
  2. Add the key manually
  3. If its a discord bot and you are making a custom prefix thingy, simply kick the bot and invite it again (you need the on_guild_join part for this)
#

KeyError: '890976262452047872'

novel rampart
#

what is the error

boreal ravine
ocean leaf
novel rampart
ocean leaf
novel rampart
#

this is the code

boreal ravine
novel rampart
#

what

paper bane
#

Example has to be a defined class above the setup function

boreal ravine
#

^ meaning ur cog name

novel rampart
# boreal ravine did u define it?
import discord
from discord.ext import commands


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


    @commands.Cog.listener()
    async def on_ready(self):
        print('Bot is online now')


def setup(bot):
    bot.add_cog(Example(bot))
#

this is the full code i added in cogs

boreal ravine
novel rampart
#

oh ok

novel rampart
#

that error solved

boreal ravine
#

ok

orchid talon
#

Which commands shoul I use for auto role when member join

boreal ravine
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") leaves or joins 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.
orchid talon
#

Ty

slate swan
#

hi

#

Send the dm first

#

nvm

ocean leaf
#

ik now i got it 😂 thats why i deleted it

slate swan
#

yeah lmao

waxen granite
#

Can a bot owner use commands with .has_perms() in a guild in which the owner doesnt have required perms?

novel rampart
#

what is the erorr

slate swan
novel rampart
#

oh ok

#

i find it thanks

slate swan
#

np

boreal ravine
manic wing
#

you might have to elaborate

slate swan
#

@waxen granite check if the authors is the bot owner

#

Or make a function to check it

#

Or use the decorator

#

Such as @commands.is_owner() or @bot.is_owner() depending on if you're in a cog or not

manic wing
#

or put all owner-only commands in a cog, save time and do py async def check(self, ctx): if ctx.author.id not in self.bot.owner_ids: return False return True

visual island
#

you can just return ctx.author.id in self.bot.users

manic wing
dapper cobalt
#

It's readable if who's reading is good at Python.

slate swan
#

.users returns all the users the bot can see, shouldn't it be .owner_id based on their question 🤔

manic wing
slate swan
#

¯\_(ツ)_/¯

visual island
atomic topaz
#

I'm making a discord bot using python, and I wanted to add a command to create a text channel.

And I wanted to check if the channel exists or not but I'm not able to do so

So can anyone help me with this?

visual island
#
if utils.get(guild.channels, name="Channel-Name") is None:
  guild.create_text_channel(...) 
```or smth like that
atomic topaz
#

oh thanks let me try

#

ah sorry but idk it's still not working

#

I don't have any error but I created a channel that already exists and the bot created that wasn't supposed to

#
  existing_channel = discord.utils.get(guild.channels, name=channel_name)
  if existing_channel == None:
#

i tried this too

#

still not working

gloomy coral
waxen granite
slate swan
#

check_any checks for both

waxen granite
#

Hm

slate swan
#

if even one is true it'll work

#

so that will work

waxen granite
#

Okay thanks, i will try it

slate swan
#

is it possible to run a music bot by playing files and the files will be randomized like run by 1 command so any 1 in 2 sound files will be played these are the codes

@bot.command()
async def fastmoans(ctx: commands.Context):
    voice_channel: discord.VoiceChannel = ctx.author.voice.channel
    print(voice_channel.name)
    vc = await voice_channel.connect()
    vc.play(discord.FFmpegPCMAudio("fast moan.mp3"))
    while vc.is_playing():
        time.sleep(.1)
    await vc.disconnect()
gloomy coral
unkempt canyonBOT
#

7. Keep discussions relevant to the channel topic. Each channel's description tells you the topic.

gloomy coral
#

!yt

unkempt canyonBOT
#

Per Python Discord's Rule 5, we are unable to assist with questions related to youtube-dl, pytube, or other YouTube video downloaders as their usage violates YouTube's Terms of Service.

For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2021-03-17:

The following restrictions apply to your use of the Service. You are not allowed to:

1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service;  (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;

3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTube’s robots.txt file; (b) with YouTube’s prior written permission; or (c) as permitted by applicable law;

9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
gloomy coral
#

@slate swan

gloomy coral
rain apex
#

Hey @gloomy coral, can we keep things on topic please?

slate swan
#

@slate swan Using FFMPEG breaks the YouTube ToS, and this server doesn't allow us to help with projects that breach any violations or ToS's, so we can't help you with it, sorry

slate swan
#

how do you check whether a member has a specific role or no

#

i guess it was something like

#

r!tag member.roles

slate swan
unkempt canyonBOT
#

property roles: List[Role]```
A [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role") that the member belongs to. Note that the first element of this list is always the default [‘@everyone](mailto:'%40everyone)’ role.

These roles are sorted by their position in the role hierarchy.
slate swan
#

if there are 2 sound files
and i want any 1 sound file to by played when a single command is used

#

how do I do that pls help

#
@bot.command()
async def test(ctx: commands.Context):
    voice_channel: discord.VoiceChannel = ctx.author.voice.channel
    print(voice_channel.name)
    vc = await voice_channel.connect()
    vc.play(discord.FFmpegPCMAudio("song"))
    while vc.is_playing():
        time.sleep(.1)
    await vc.disconnect()
steep estuary
#

how to connect pgadmin 4 with heroku?

slate swan
#

can someone help me out?

ionic wadi
#
    @commands.command(brief="SUPPORT TEAM+", description="Will je iemand bannen? Dat kan met dit command!")
    @commands.has_role('Support Team')
    async def ban(self, ctx, member:discord.User=None, reason =None):
        if member == None:
            await ctx.send("Je moet wel iemand opgeven.")
        if member == ctx.author:
            await ctx.send("Je kan jezelf niet bannen.")
        if reason == None:
            reason = "Geen reden opgegeven!"
        await member.ban(reason = reason)
        message = f"Je bent gebanned van {ctx.guild.name} ivm {reason}"
        await member.send(message)
        await ctx.channel.send(f"{member} is gebanned van de server!")```
#

I get no output or error, why>

#

The cog works fine btw

slate swan
#

what's the issue?

ionic wadi
#

I dont get an error thats the problem.

keen comet
#

Hmm

ionic wadi
#

But I dont get an output either.

slate swan
#

hmm

#
    @commands.command(brief="SUPPORT TEAM+", description="Will je iemand bannen? Dat kan met dit command!")
    @commands.has_role('Support Team')
    async def ban(self, ctx, member:discord.User=None, reason =None):
        if member == None:
            await ctx.send("Je moet wel iemand opgeven.")
        if member == ctx.author:
            await ctx.send("Je kan jezelf niet bannen.")
        if reason == None:
            reason = "Geen reden opgegeven!"
        else:
          await member.ban(reason = reason)
          message = f"Je bent gebanned van {ctx.guild.name} ivm {reason}"
          await member.send(message)
          await ctx.channel.send(f"{member} is gebanned van de server!")``` maybe, it's been a while since i worked with dpy
ionic wadi
#

Good idea, ill try.

slate swan
#

btw bread can you help me out with something

#
@client.event
async def on_member_join(member):
    print("You havd")
    guild1 = client.get_guild(893391320813555713)
    guild2 = client.get_guild(893330054254317698)
    role = guild2.get_role(893391786586828800)
    if role in member.roles:
        print("You have joined")
        return
    else:
        await member.kick()
        print("You have not joined")``` i want it to check if the member has role in guild2, but it instead checks in the guild1 and kicks the member instantly
#

mention me if you helped. thanks!

tropic briar
#
@client.listen
async def on_message(message, member):
  for i in range(len(Filter)):
    if Filter[i] in message.content:
      for j in range(1):
        await member.ban(reason='filter')
        await message.send('A member has been banned')
        await client.process_commands(message)
``` This is not banning when I say a word
slate swan
#

oof, that looks weird and broken

tropic briar
#

like it should find the words in the array called filter then ban if the message contains the word

tropic briar
tropic briar
slate swan
dapper cobalt
#

You can use regex.

tropic briar
#

Filter = ['giant', 'hi', 'hello', 'monke', 'bye', 'balance']

slate swan
dapper cobalt
#

One second.

tropic briar
slate swan
# tropic briar Here is the variable I have created
async def on_message(message, member):
  for words in Filter:
    if words in message.content:
        await member.ban(reason='filter')
        await message.send('A member has been banned')
        await client.process_commands(message)
     else:
          return``` maybe try this?
tropic briar
#

let's see

slate swan
#

indention looks messed up

#

(mine indention)

dapper cobalt
#

!e

import re

bad_words = ["word 1", "word 2"]
message = "word 1 is a bad word"
for word in bad_words:
  found = re.find(word, message)
  if not found:
    continue
  print(f"Detected word '{word}'")
unkempt canyonBOT
#

@dapper cobalt :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 6, in <module>
003 | AttributeError: module 're' has no attribute 'find'
dapper cobalt
#

!e

import re

bad_words = ["word 1", "word 2"]
message = "word 1 is a bad word"
for word in bad_words:
  found = re.search(word, message)
  if not found:
    continue
  print(f"Detected word '{word}'")
unkempt canyonBOT
#

@dapper cobalt :white_check_mark: Your eval job has completed with return code 0.

Detected word 'word 1'
dapper cobalt
#

!d re.search

unkempt canyonBOT
#

re.search(pattern, string, flags=0)```
Scan through *string* looking for the first location where the regular expression *pattern* produces a match, and return a corresponding [match object](https://docs.python.org/3.10/library/re.html#match-objects). Return `None` if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string.
dapper cobalt
#

You can use this.

slate swan
slate swan
#

please someone help, can ya?

slate swan
dapper cobalt
slate swan
#

yes

dapper cobalt
#

And you are checking member.roles.

#

While the role is in guild2.

slate swan
#

Yes

dapper cobalt
#

member.roles will return the member's roles in guild1 and not guild2.

#

And you are trying to check if they have a role that's not even in the guild they joined.

slate swan
#

yes i understand

tropic briar
dapper cobalt
#

You are telling it to search for a keyword in a string.

slate swan
dapper cobalt
#

!d discord.Guild.get_member

unkempt canyonBOT
tropic briar
#
@client.listen
async def on_message(message, member):
  for i in range(len(Filter)):
    if Filter[i] in message.content:
      for j in range(1):
        await member.ban(reason='filter')
        await message.send('A member has been banned')
        await client.process_commands(message)
``` Can I not make this work
slate swan
#

oh nvm

dapper cobalt
#

Filter is a list which is iterable.

tropic briar
dapper cobalt
#
for item in array:
  ...
slate swan
#

@dapper cobalt can you give me a very short example

dapper cobalt
#
for i in Filter:
  if i in message.content:
    await member.ban(reason="filter")
dapper cobalt
slate swan
#
guild2 = client.get_guild(893330054254317698)
    role = guild2.get_role(893391786586828800)
    members = guild2.get_member(member)
    if role in members.roles:
        print("You have joined")
        return``` i am trying this
dapper cobalt
#

You are not getting the member correctly.

slate swan
#

oh

dapper cobalt
#

You need to use the member's ID.

slate swan
#

it's working now thanks!

tropic briar
#
@client.listen
async def on_message(message, member):
  for i in range(len(Filter)):
    for i in Filter:
      if i in message.content:
        await member.ban(reason="filter")
dapper cobalt
#

!d discord.Guild.get_member

unkempt canyonBOT
tropic briar
#

you told me this ig

dapper cobalt
#
@client.listen
async def on_message(message):
  for i in Filter:
    if i in message.content:
      await message.author.ban(reason="filter")
tropic briar
#

So first we make a function

#

then check if i is in Filter or not

#

and i is in filter

delicate heart
#

HELP

tropic briar
#

then we ban

dapper cobalt
#

for every_word in this_list_of_words

#

!e

list_of_names = ["seif wessam", "giant", "scoopy"]
for name in list_of_names:
  print(name)
unkempt canyonBOT
#

@dapper cobalt :white_check_mark: Your eval job has completed with return code 0.

001 | seif wessam
002 | giant
003 | scoopy
tropic briar
#

array is 3 * 1 so we loop thrice

dapper cobalt
#

Loop through the array instead.

tropic briar
#

ya i see that

solemn grove
#

How to get the number of invites of the user?

dapper cobalt
#

message.content is a string, you are going through each word (i) in your list Filter and you check if this word is in the message.content.

slate swan
#

one last thing, how can i make it like it should only work if the person joined a specific server

dapper cobalt
slate swan
#

i don't get it

dapper cobalt
tropic briar
#
Filter = ['giant', 'hi', 'hello', 'monke', 'bye', 'balance']

@client.listen
async def on_message(message):
  for i in Filter:
    if i in message.content:
      await message.author.ban(reason="filter")
      await message.send("You are banned")
``` I don't see this working when I say hi
dapper cobalt
#

Learn Python.

slate swan
#

i am sorry, i haven't used dpy in ages and i've understood what's the issue

tropic briar
#

No

dapper cobalt
#

Are you the server's owner? Or is your role higher than the bot's role?

tropic briar
#

yes I am

#

I am the server owner

cloud dawn
#

!source

unkempt canyonBOT
tropic briar
#

but the should atleast reply the message

dapper cobalt
#

Then I will ask you a genuine question. Are you able to ban a server's owner even if you had administrator permissions?

tropic briar
#

I am not fool the bot is not even saying You are banned

slate swan
#

how do I make my bot send a thank you message to DM when it gets an upvote from their voting site using webhooks

tropic briar
#
Filter = ['giant', 'hi', 'hello', 'monke', 'bye', 'balance']

@client.listen
async def on_message(message):
  for i in Filter:
    if i in message.content:
      await message.author.ban(reason="filter")
      await message.send("You are banned")
dapper cobalt
#

That's first. Second, when you get banned, the message will be deleted. Which will raise "Unknown Message" error.

tropic briar
#

The bot should say You are bammed

dapper cobalt
#

And third, discord.Message has no method called send().

#

And fourth, the ban operation has raised an error, which will stop the rest of the code after it.

tropic briar
#

hmm

#

ctx.send?

dapper cobalt
#

What is ctx defined as?

slate swan
dapper cobalt
#

Is this a command? Or an event?

slate swan
#

it mean context basically what is going

dapper cobalt
#

But that's an event, how would it have a context?

#

!d discord.ext.commands.Context

unkempt canyonBOT
#
class discord.ext.commands.Context(*, message, bot, view, args=..., kwargs=..., prefix=None, command=None, invoked_with=None, invoked_parents=..., invoked_subcommand=None, ...)```
Represents the context in which a command is being invoked under.

This class contains a lot of meta data to help you understand more about the invocation context. This class is not created manually and is instead passed around to commands as the first parameter.

This class implements the [`Messageable`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable "discord.abc.Messageable") ABC.
slate swan
#

like

await ctx.send('wut you wanna send') 
#

you can put this line in any event or command

tropic briar
slate swan
dapper cobalt
slate swan
#

At least use the resources tag

dapper cobalt
dapper cobalt
dapper cobalt
#

It's either message.reply() or message.channel.send().

#

!d discord.Message

unkempt canyonBOT
#

class discord.Message```
Represents a message from Discord.

x == y Checks if two messages are equal.

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

hash(x) Returns the message’s hash.
dapper cobalt
#

Delete this, please. 🙂

slate swan
#

That's because ctx is passed in a perimeter

dapper cobalt
#

Make it able to ban the user first. And then message.channel.send().

dapper cobalt
slate swan
#

Which is discord.ext.commands.Context

#

I see thanks

slate swan
tropic briar
#

ok

dapper cobalt
bitter depot
# dapper cobalt Learn Python.

Let's not be so dismissive of people who are new to Python please. I get that it can be frustrating, but you can be a lot more helpful than just "learn Python". Remember there's no obligation to help anyone either, so there's always the option to let someone else help the newer users.

dapper cobalt
slate swan
#

can anyone help me how do I make my discord bot send a thank you message to their when they get upvote from their upvoting site i am using webhooks for this purpose
These are the codes

import re

@bot.event
async def on_message(message):
    if message.channel.id == 834837773805813780:
        data = message.content.split(" ")
        user = re.sub("\D", "", data[0])

    await bot.process_commands(message)
#

Hello how to get a server object?

dapper cobalt
unkempt canyonBOT
#

class discord.Guild```
Represents a Discord guild.

This is referred to as a “server” in the official Discord UI.

x == y Checks if two guilds are equal.

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

hash(x) Returns the guild’s hash.

str(x) Returns the guild’s name.
slate swan
#

Using server id

dapper cobalt
#

!d discord.ext.commands.Bot.get_guild

unkempt canyonBOT
slate swan
#

Can I get the owner name and member count from that obj?

slate swan
#

!d discord.Guild.owner

unkempt canyonBOT
#

property owner: Optional[discord.member.Member]```
The member that owns the guild.
slate swan
#

!d discord.Guild.members

unkempt canyonBOT
#

property members: List[discord.member.Member]```
A list of members that belong to this guild.
dapper cobalt
#

!d discord.Guild click on the blue title and you will see it on the docs.

unkempt canyonBOT
#

class discord.Guild```
Represents a Discord guild.

This is referred to as a “server” in the official Discord UI.

x == y Checks if two guilds are equal.

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

hash(x) Returns the guild’s hash.

str(x) Returns the guild’s name.
dapper cobalt
slate swan
dapper cobalt
slate swan
#

i am not getting any data actually

dapper cobalt
#

Then most likely it fails to send a POST request to your webhook URL.

slate swan
#

i have also connected a discord webhook within HTTP

dapper cobalt
#

I'm not very familiar with that.

slate swan
#

the site helpers gave me a doc but he said it wont show how to send DM but use this as a ref

dapper cobalt
#

Well, first of all, you need to receive some data. Then, if the data includes the voter's ID, sending them a private message would be easy. Just get the user from the bot's cache using their ID, and send them the message.

slate swan
#

what do you think?

#

who has the issue the code or the webhook codes

dapper cobalt
#

What code?

dapper cobalt
slate swan
#

do you think is there any way to fix it?

dapper cobalt
#

How do you receive the POST request?

#

What?

#

What does that have to do with Python at all?

slate swan
#

the site isnt having an API for that which makes it even a bigger problem

#

1st dpy and now entire python?

#

oh

dapper cobalt
slate swan
#

dpy stopped dev it means discord is also stopping dpy?

#

dpy doesnt supp slash commands

#

WAIT WHAT?

dapper cobalt
#

Then just type / and you will see all your bot's slash commands.

slate swan
#

i heard that the only reason why dpy stopped dev was due to discord was making all languages slashes

dapper cobalt
#

It's up to you whether you want to make a help command.

#

But I believe it's useless since it's slash commands.

slate swan
#

I see

#

have anyone heard about discordbotlist?

dapper cobalt
#

I'd go with disnake. It's pretty good imo. And also it supports all kinds of Discord interactions.

slate swan
#

i see

#

dank memer?

dapper cobalt
slate swan
dapper cobalt
#

Yeah, my bot's listed there.

slate swan
#

i tried to understand it but everything gone above my brain

sick talon
#

on_voice_update isn't working

@client.event
async def on_voice_update(member,before,after):
  if member.bot:
    return
  if not before.channel:
    print(f"{member.name} joined {after.channel.name}")
  if before.channel and not after.channel:
    print(f"{member.name} left {before.channel.name}")
  if before.channel and after.channel:
    if before.channel != after.channel.id:
      print(f"{member.name} swicthed voice channel")
    else:
      print("Something else happened")
slate swan
#

delete message or we get mute or ban

#

no risk

#

play safe

dapper cobalt
boreal ravine
#

!d discord.on_voice_state_update

unkempt canyonBOT
#

discord.on_voice_state_update(member, before, after)```
Called when a [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") changes their [`VoiceState`](https://discordpy.readthedocs.io/en/master/api.html#discord.VoiceState "discord.VoiceState").

The following, but not limited to, examples illustrate when this event is called...
slate swan
boreal ravine
dapper cobalt
slate swan
#

and the way to make a DM when get upvote

#

can you please check if its possible for python because dank memer is JS

boreal ravine
#

dunno

#

use an api or something?

slate swan
#

i suffer from brain pain,dizzyness when lookin on js codes

slate swan
slate swan
#

{

100 lines of codes with bunch of ( , . /

}

dapper cobalt
slate swan
boreal ravine
boreal ravine
slate swan
#

nah i guess

dapper cobalt
slate swan
#

i ned to go

boreal ravine
#

Those are just python parentheses in javascript.

tropic briar
#

How can I make my bot send message in On_message function

maiden fable
tropic briar
#

ok

tropic briar
# maiden fable message.channel.send()
@client.listen
async def on_message(message):
  for i in Filter:
    if i in message.content:
      await message.channel.send('hmm') 
      await message.send("You are banned")
``` But the bot doesn't replies
#

Filter is a list of some words

maiden fable
#

Ah

dapper cobalt
#

Do you send "hi" or "Hi"?

#

Use message.content.lower() instead of message.content.

tropic briar
#

yes I send

tropic briar
dapper cobalt
#

Code?

tropic briar
#
@client.listen
async def on_message(message):
  for i in Filter:
    if i in message.content.lower()
      await message.channel.send('hmm') 
      await message.send("You are banned")
dapper cobalt
#

What do you think your problem is?

#

Take a close look at your code.

tropic briar
#

I really think that there is no problem

dapper cobalt
#

There is.

tropic briar
#

:?

dapper cobalt
#

And I've spotted it once you sent the code. Just look closer.

tropic briar
#

:

dapper cobalt
#

Yes.

tropic briar
#

lemme try now

maiden fable
#

Me who smashes my head in a wall when I miss a closing bracket: pithink

amber imp
#
    @commands.command()
    async def blur(self, ctx):
        img = Image.open('C:/bots/studybot/cogs/test.png')
        img2 = img.filter(CONTOUR)
        await ctx.send(img2)
```help pls
#

i want to send a image

tropic briar
#

and the bot doesn't replies

amber imp
#

but it sends this

#

<PIL.Image.Image image mode=RGBA size=720x592 at 0x1BD3562A2B0>

tropic briar
#
@client.listen
async def on_message(message):
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('hmm') 
      await message.send("You are banned")
dapper cobalt
#

Try to print the message.content at the start of the function.

tropic briar
#

ok

#

print(message.content) ?

dapper cobalt
#

No, System.out.println(message.content);.

#

I'm just kidding, yes.

tropic briar
#

lol ok

maiden fable
dapper cobalt
sweet plover
#

aint that java

maiden fable
sweet plover
#

lul bit too late

maiden fable
amber imp
slate swan
#

sooo

dapper cobalt
maiden fable
#

😂

sweet plover
#

xD

slate swan
#

I got these codes from dank memer github where it showed how to send user a thank you message is it possible to convert these into python?

return _saveQuery(_fetchUserQuery(id).merge({
    voteReminderWaiting: true,
    pocket: r.row('pocket').default(0).add(50000),
    inventory: {
        [itemOne]: r.row('inventory').default({}).getField('banknote').default(0).add(3),
        [itemTwo]: r.row('inventory').default({}).getField('daily').default(0).add(1)
      },
    upvoted: true,
    ...(isDbl
        ? { lastDblVote: Date.now() }
        : { lastTopggVote: Date.now() }
      )
  })).run();
};
dapper cobalt
#

!d PIL.Image

unkempt canyonBOT
tropic briar
#
@client.listen
async def on_message(message):
  for i in Filter:
    if i in message.content.lower():
      print(message.content)
      await message.channel.send('hmm') 
      await message.send("You are banned")
``` This is my code and bot doesn't prints
dapper cobalt
tropic briar
#

before the first for?

sweet plover
#

yea

slate swan
# maiden fable Dank Memer is open source?

idk about that but in dank memer github it showed webhooks in which there was upvote.js and i checked what dank memer DM when we vote for him and found these codes were behind it

dapper cobalt
#

Yes.

keen talon
sweet plover
#

how can i send a message in on_ready?
already tried

await channel.send('hello')```
and
`await client.get_channel("enter channel id here").send("bot is online")`
#

didnt work

tropic briar
#
@client.listen
async def on_message(message):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('hmm') 
      await message.send("You are banned")
``` nothing changed
dapper cobalt
tropic briar
#

no it doens't

#

I tried printing so many messages

dapper cobalt
#

Replace @client.listen with @client.event.

sweet plover
#

i dont know, but try @client.event

dapper cobalt
#

!d discord.ext.commands.Bot.listen

unkempt canyonBOT
#

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

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

Example...
tropic briar
dapper cobalt
#

You weren't calling listen().

#

@client.listen("on_message")

#

Yep.

dapper cobalt
#

Or just @client.listen().

#

You just have to call it.

ionic wadi
#

File "/home/container/bot.py", line 137, in on_message
with open('/json/users.json', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'users.json'

The file exists, but why this error then?

tropic briar
#
@client.listen("message")
async def on_message(on_message):
  print(client.message)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('hmm') 
      await message.send("You are banned")
sick talon
tropic briar
#

oh yeh

dapper cobalt
#

!d discord.on_voice_state_update

unkempt canyonBOT
#

discord.on_voice_state_update(member, before, after)```
Called when a [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") changes their [`VoiceState`](https://discordpy.readthedocs.io/en/master/api.html#discord.VoiceState "discord.VoiceState").

The following, but not limited to, examples illustrate when this event is called...
sick talon
dapper cobalt
#

You were using on_voice_update.

sick talon
#

noticed it right now

#

thanks :)

tropic briar
#

Finally

#

My bot started speaking

sick talon
tropic briar
#

😄

dapper cobalt
#

Yes.

tropic briar
#

Now time to ban myself if I say hi

dapper cobalt
tropic briar
#

I know about it just kidding maybe

#

So let's ban others if they say hi

dapper cobalt
#

Ah, okay.

dapper cobalt
tropic briar
#

I am kinda joking

#

also Thanks a lot for your help

sweet plover
#

how can i send a message in on_ready?
already tried

await channel.send('hello')```and
`await client.get_channel("enter channel id here").send("bot is online")`
tropic briar
#

You told me How to ban

#
await member.ban(reason=reason)
``` Should I just put this
#

i should remove that reason

sweet plover
#

no
else i wouldn't have asked right?

boreal ravine
boreal ravine
#

that got*

tropic briar
boreal ravine
#

then remvoe it ig

sweet plover
#
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "/home/pi/Desktop/Quotes.py", line 19, in on_ready
    await client.get_channel("861677744956768290").send("!calibrating " + text)
AttributeError: 'NoneType' object has no attribute 'send'```
boreal ravine
tropic briar
#
@client.listen("on_message")
async def on_message(message, member):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('hmm') 
      await member.ban('filter')
``` Will this work ?
boreal ravine
#

change it an an int

#

not string lol

sweet plover
#

got told that solution with a string lmao

boreal ravine
#

IDs are integers

#

not strings

sweet plover
sweet plover
boreal ravine
gloomy coral
#

pinged

tropic briar
#

How can I ban someone by using the on_message function

#
@client.listen("on_message")
async def on_message(message):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
#

ok

#

ya

#
@client.listen("on_message")
async def on_message(message, member):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
      await message.guild.ban(member) 
jade jolt
#

????

#

its member.ban()

tropic briar
#

oh

#
@client.listen("on_message")
async def on_message(message, member):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
      await message.ban(member) 
jade jolt
#

member not message

tropic briar
#

huh?

#

oh yeh

jade jolt
#

on_message doesnt take a member arg

dapper cobalt
#

!d discord.on_message doesn't take a member parameter.

unkempt canyonBOT
#

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

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

Warning

Your bot’s own messages and private messages are sent through this event. This can lead cases of ‘recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that [`Bot`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
dapper cobalt
#

It's message.author.ban() and not member.ban().

jade jolt
#

he didnt explicitly say that

tropic briar
#
@client.listen("on_message")
async def on_message(message, member):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
      await member.author.ban(member)
#

this isn't working

dapper cobalt
#

You didn't even read correctly.

tropic briar
#

oh

tropic briar
#
@client.listen("on_message")
async def on_message(message, member):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
      await message.author.ban() 
#

Still

tropic briar
#
@client.listen("on_message")
async def on_message(message, member):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
      await message.author.ban(member) 
#

I have member parameter

dapper cobalt
#

!d discord.on_message can you please click on the blue title?

unkempt canyonBOT
#

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

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

Warning

Your bot’s own messages and private messages are sent through this event. This can lead cases of ‘recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that [`Bot`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
tropic briar
#

@client.listen("on_message")
async def discord.on_message(message, member):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
      await message.author.ban(member) 
#

this?

dapper cobalt
#

Do you see any member parameter?

tropic briar
#

no

#

Ok I have to remove it

dapper cobalt
#

Yes.

#

And don't forget to remove it from message.author.ban().

tropic briar
#
@client.listen("on_message")
async def on_message(message):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
      await message.author.ban() 
#

Not working

dapper cobalt
#

Does it print the message's content?

tropic briar
#

no

#

It's not even replying now

dapper cobalt
#

Try removing "on_message" from the listen() function.

tropic briar
#

ok

#

Wait

#

It prints but it doesn't ban and reply

dapper cobalt
#

It replies?

tropic briar
#
@client.listen()
async def on_message(message):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      await message.channel.send('Time to ban you out')
      await message.author.ban() 
#

no it doesn't

#

It don't say 'Time to ban you out'

dapper cobalt
#

Hey, add this:

@client.event
async def on_command_error(ctx, error):
  raise error
#

Not very sure if this applies to errors of message events as well, but hopefully it does.

tropic briar
#

Nothing changed

dapper cobalt
#

That's just so it will start logging commands errors.

#

Can I see your console?

tropic briar
#

ok

dapper cobalt
#

Make it print i.

tropic briar
#
@client.listen()
async def on_message(message):
  print(message.content)
  for i in Filter:
    if i in message.content.lower():
      print(i)
      await message.channel.send('Time to ban you out')
      await message.author.ban() 
dapper cobalt
#
for i in Filter:
  print(i)
tropic briar
#

It prints all the filters

#

with the message content @dapper cobalt

boreal ravine
#

Maybe check ur old code and see what u did for roles = self.roles.get(message)? that usually helps for me lol

novel rampart
#

what is the error

opaque trail
#

VoiceClient.play raises an OpusError: invalid argument? works fine on other operating system, using macos

novel rampart
#

i know that error is name error

#

but i don't found that

#
lastmsg={}
    @commands.Cog.listener()
    async def on_message_delete(message:discord.Message):
        lastmsg[message.guild.id]=message
high flame
#

Filter not defined

novel rampart
#

this is code

novel rampart
#

yes

tropic briar
novel rampart
#

why

tropic briar
#
@client.listen()
async def on_message(message):
  print(message.content)
  for i in Filter:
    print(i)
    if i in message.content:
      print(i)
      await message.channel.send('Time to ban you out')
      await message.author.ban() 
``` Why is the if not working
novel rampart
#

i am converting my code into cogs

boreal ravine
#

show the cog

novel rampart
#

ok

novel rampart
# boreal ravine show the cog
class Snipe(commands.Cog):
    def __init__(self, bot):
        self.bot = bot


    lastmsg={}
    @commands.Cog.listener()
    async def on_message_delete(message:discord.Message):
        lastmsg[message.guild.id]=message

    @commands.command()
    async def snipe(self, ctx:commands.Context):
        try:
            author = lastmsg[ctx.message.guild.id].author.mention
            content = lastmsg[ctx.message.guild.id].content
            channel = lastmsg[ctx.message.guild.id].channel.mention
            embed = discord.Embed(title = ":gun:Hitman Snipes a message!!:gun:\n\n",description = f"**Author**\n{author}\n\n**Message**\n`{content}`\n\n**Channel**\n{channel}\n\n")
            embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url)
            await ctx.send(embed = embed)
        except KeyError:
            await ctx.send(f"No Messages to delete in {ctx.channel.mention}")
novel rampart
boreal ravine
#

put the lastmsg variable on the same line as self.bot

dapper cobalt
boreal ravine
novel rampart
tropic briar
novel rampart
#

what you say

boreal ravine
ionic wadi
#
class WIP(commands.Cog, name='WIP (SOON)'):
    def __init__(self, bot):
        self.bot = bot
        
    @commands.command()
    @commands.has_role("Support Team")
    async def announce(self, ctx, msg=None, channel=None):
        await ctx.send("Wat is het bericht?", delete_after=3.0)
        try:
            message = await bot.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=45.0)
        except asyncio.TimeoutError:
            await ctx.send("Helaas reageerde je niet binnen 45 seconde! En de prompt is beeindigd.")
        else:
            msg = message.content
            await ctx.send("Welk kanaal will je het in hebben?", delete_after=3.0)
            try:
                message = await bot.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout=190.0)
            except asyncio.TimeoutError:
                await ctx.send("Helaas reageerde je niet binnen 190 seconde! En de prompt is beeindigd.")
            else:
                channel = message.content
                await ctx.send("Ik ga het bericht verturen.", delete_after=3.0)
                await channel.send(msg)```

The prompt works but It doesnt send the message
#

and I dont get an error

boreal ravine
novel rampart
#

oh ok

#

lemme check

dapper cobalt
#

Did you mean channel = message.channel?

tropic briar
#

hi
False
False
False
False

ionic wadi
#

good one

#

No I didnt

#

I want them to mention the channel in the content

#

and send it there

tropic briar
tropic briar
#
@client.listen()
async def on_message(message):
  print(message.content)
  for i in Filter:
    print(i in message.content.lower())
    if i in message.content:
      print('hi')
      await message.channel.send('Time to ban you out')
      await message.author.ban() 
``` @dapper cobalt
novel rampart
#

comes

boreal ravine
novel rampart
#

the same error

#

name error

boreal ravine
#

show code

novel rampart
#

mm

novel rampart
# boreal ravine show code
class Snipe(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        lastmsg = {}



    @commands.Cog.listener()
    async def on_message_delete(message:discord.Message):
        lastmsg[message.guild.id]=message

    @commands.command()
    async def snipe(self, ctx:commands.Context):
        try:
            author = lastmsg[ctx.message.guild.id].author.mention
            content = lastmsg[ctx.message.guild.id].content
            channel = lastmsg[ctx.message.guild.id].channel.mention
            embed = discord.Embed(title = ":gun:Hitman Snipes a message!!:gun:\n\n",description = f"**Author**\n{author}\n\n**Message**\n`{content}`\n\n**Channel**\n{channel}\n\n")
            embed.set_footer(text=f"Made by {ctx.author.display_name}.", icon_url=ctx.author.avatar_url)
            await ctx.send(embed = embed)
        except KeyError:
            await ctx.send(f"No Messages to delete in {ctx.channel.mention}")
#

this is the code

boreal ravine
#

hmm

slate swan
#

lastmsg should be self.lastmsg

#

That's why u get the error

boreal ravine
#

oh yeah

#

o-o

slate swan
#

Also your on_message_delete is missing self

novel rampart
novel rampart
boreal ravine
slate swan
tropic briar
#

@dapper cobalt bro thanks a lot lot lot because now everything is working and I even banned Dank Memer for saying "need" Thanks a lot

#

this is the code

@client.listen()
async def on_message(message):
  print(message.content)
  for i in Filter:
    if i in message.content:
      print('hi')
      await message.channel.send('Time to ban you out')
      await message.author.ban() 
slate swan
slate swan
boreal ravine
#

if ctx.guild.id == id:

#

those are for commands and no there isnt a way to hide slash commands yet

solemn grove
#

How to mention the mentioned user?

amber imp
#
  @commands.command()
    async def wanted(self, ctx, user: discord.Member = None):
        if user == None:
            user = ctx.author

        wanted = Image.open("C:/bots/studybot/cogs/wanted.PNG")

        asset = user.avatar_url_as(size=128)
        data = BytesIO(await asset.read())
        pfp = Image.open(data)
        pfp = pfp.resize(111, 171)

        wanted.paste(pfp, (105,327))

        wanted.save("profile.PNG")
        await ctx.send(file=discord.File("profile.PNG"))
#

help please

#
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\bots\studybot\cogs\fun.py", line 121, in wanted
    pfp = pfp.resize(111, 171)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py", line 1899, in resize
    raise ValueError(
ValueError: Unknown resampling filter (171). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)

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

Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: Unknown resampling filter (171). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)
slate swan
#

every single time i try run my bot it says it has a invalid token

#

its right

#

Do you use env?

#

i have checked like 50 times

#

and regenerated50 times

slate swan
#

i have a host

#

so i dont need too

#

do you put it directly in the code

#

ohok

slate swan
#

can you send the trackback

#

i do token = "token here" and client.run(token)

#

are you sure that you regenerate and copy it ?

slate swan
#

i reveal it too

amber imp
boreal ravine
slate swan
#

and look at it

boreal ravine
slate swan
boreal ravine
slate swan
#

50 times

boreal ravine
#

o.o

slate swan
amber imp
#

i not got any error

slate swan
#

i think im blacklisted

#

or something

#

idk what for

#

it would not have sent improper token error

slate swan
#

in case you were banned from accessing the api

#

same error

amber imp
boreal ravine
boreal ravine
#

no pinging random ppl

amber imp
#

im not pinging

boreal ravine
#

smh ok

amber imp
#

ok

solemn grove
#

How to mention the mentioned user?

slate swan
# amber imp i think u overided <@78923588530343936>.event
@client.event
async def on_ready():
    print('Connected to bot: {}'.format(client.user.name))
    print('Bot ID: {}'.format(client.user.id))
    await client.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name=f">commands"))
``` this is the only client event i have
slate swan
unkempt canyonBOT
amber imp
#
@commands.command()
    async def wanted(self, ctx, user: discord.Member = None):
        if user == None:
            user = ctx.author

        wanted = Image.open("C:/bots/studybot/cogs/wanted.PNG")

        asset = user.avatar_url_as(size=128)
        data = BytesIO(await asset.read())
        pfp = Image.open(data)
        pfp = pfp.resize(171, 171)

        wanted.paste(pfp, (105, 327))

        wanted.save("profile.PNG")
        await ctx.send(file=discord.File("profile.PNG"))
#

can anyone help me

slate swan
#

and i wouldn't save images in cogs

amber imp
# slate swan whats the traceback?
Ignoring exception in command wanted:
Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\bots\studybot\cogs\fun.py", line 121, in wanted
    pfp = pfp.resize(171, 171)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py", line 1899, in resize
    raise ValueError(
ValueError: Unknown resampling filter (171). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)

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

Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: Unknown resampling filter (171). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)

Process finished with exit code -1```.
amber imp
boreal ravine
slate swan
#

justi would seperate them

boreal ravine
slate swan
#

otherwise its messy

high flame
#

mhm

boreal ravine
#

hm

boreal ravine
#

I mean its a resizing issue

amber imp
#

yes

visual island
amber imp
#

ok

amber imp
high flame
#

show what you did

amber imp
high flame
#

yeah

#

and full traceback

#

in code block

amber imp
#

ok

visual island
high flame
#

:rooBulli:

visual island
amber imp
# high flame and full traceback
Ignoring exception in command wanted:
Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\bots\studybot\cogs\fun.py", line 121, in wanted
    pfp = pfp.resize(171,171)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\PIL\Image.py", line 1899, in resize
    raise ValueError(
ValueError: Unknown resampling filter (171). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)

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

Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: Unknown resampling filter (171). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)
high flame
#

fk clyde

amber imp
#

waitbro

high flame
#

resize(<list/tuple or whatever>)??

amber imp
#

ohh

#

wait

visual island
visual island
#

lol

#

if the pfp is animated, you can't use that code potato_popcorn (just telling)

amber imp
high flame
#

i can't use roo emojis anymore ;-;

visual island
high flame
#

lmao

visual island
#

potato is cuter tbh

high flame
#

yeah but i love some roo emojis

topaz sierra
#

How can I count a member's message in total?

high flame
#

like :rooDuck:

#

Clyde again :(

visual island
boreal ravine
#

Code: ```py
@commands.command(description='Says whatever you want using a webhook.')
async def echo(self, ctx, *, message):
webhook = await ctx.channel.create_webhook(name=ctx.author.name, avatar=ctx.author.avatar)
await ctx.message.delete()
await webhook.send(message)
await asyncio.sleep(0.5)
await webhook.delete()

Error: ```py
Command raised an exception: AttributeError: 'Asset' object has no attribute 'startswith'
high flame
#

full traceback

boreal ravine
#

it isnt a traceback

high flame
#

then what bruh

boreal ravine
#

thats the full error

topaz sierra
#

Thanks

visual island
high flame
visual island
#

you used an eval?

boreal ravine
#

no?

high flame
boreal ravine
#

the console

high flame
#

avatar is an Asset

boreal ravine
high flame
#

do avatar.url

#

avatar=ctx.author.avatar.url

boreal ravine
#

aight

#

hmmm

visual island
#

avatar (Optional[bytes]) the param should accept bytes

#

not string

high flame
#

hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

boreal ravine
#
Command raised an exception: TypeError: startswith first arg must be str or a tuple of str, not bytes
``` wot
high flame
#

!d discord.TextChannel.create_webhook

unkempt canyonBOT
#

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

Creates a webhook for this channel.

Requires [`manage_webhooks`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_webhooks "discord.Permissions.manage_webhooks") permissions.

Changed in version 1.1: Added the `reason` keyword-only parameter.
boreal ravine
#

wot

visual island
boreal ravine
visual island
#

raise error dont do print(error)

boreal ravine
#

hm

high flame
high flame
visual island
visual island
high flame
#

k

unkempt canyonBOT
#

discord/asset.py line 54

async def read(self) -> bytes:```
high flame
#

umm K

boreal ravine
# visual island do you see the difference?

hm```py
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 351, in _run_event
await coro(*args, **kwargs)
File "/home/runner/bot/main.py", line 66, in on_command_error
raise error
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 994, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 894, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 176, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: startswith first arg must be str or a tuple of str, not bytes

high flame
#

show what you did

solemn grove
#

How to make the bot trigger on every message?

boreal ravine
high flame
unkempt canyonBOT
#

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

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

Warning

Your bot’s own messages and private messages are sent through this event. This can lead cases of ‘recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that [`Bot`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
stark bobcat
#

hlo

boreal ravine
#

hey

boreal ravine
stark bobcat
#
if content == 'yes':
            await ctx.author.send('Ticket created')
            try:
                channel = self.bot.get_channel(self.bot.logs_channel.id)
                await channel.send('ye a guy made a ticket ig')

            except Exception as e:
                print(e)
               

        if content == 'no':
            await ctx.author.send('Cancelled')```
#

this is the which does not work

#

and the var is defined in another file

boreal ravine
#

hm

stark bobcat
boreal ravine
#

or in another one

stark bobcat
stark bobcat
boreal ravine
#

hm

stark bobcat
#

i am importing server_setup

#

from cogs.server_setup import *

#

like this

frozen forum
#

whait what

#

why is that red even tho Its the same

jade jolt
#

wrong indent level

frozen forum
#

What does that mean ?

slate swan
frozen forum
# slate swan @commands.command and async def should be in same level

wait like this ?

import discord
from discord.ext import commands
import youtube_dl

class music(commands.Cog):
   def __init__(self, client) :
     self.client = client

     @commands.command()
     async def join(self,ctx) :
          if ctx.author.voice is None:
             await ctx.send("You're not in an voice channel!")
          voice_channel = ctx.author.voice.channel
          if ctx.voice_client is None:
             await voice_channel.connect()
          else:
               await ctx.voice_client.move_to(voice_channel)

    @commands.command() async def disconnect(self,ctx) :
      await ctx.voice_client.disconnect()
    

     def setup(client):
          client.add_cog(music(client))
jade jolt
#

they're in the __init__ function too

slate swan
unkempt canyonBOT
#

Indentation

Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.

Example

def foo():
    bar = 'baz'  # indented one level
    if bar == 'baz':
        print('ham')  # indented two levels
    return bar  # indented one level

The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.

Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines

More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation

frozen forum
#

man I rly am dumb I still cnat get it

slate swan
frozen forum
#

?

slate swan
#

maybe try to learn basic python before going into discord.py

slate swan
# frozen forum
    async def disconnect(self,ctx) :
      await ctx.voice_client.disconnect()```
jade jolt
#

lol

#

stick to PEP 8

frozen forum
#

same error

slate swan
frozen forum
slate swan
#

u just copy pasted the code from somewhere thats why

#

this is why you shouldnt copy paste codes

#

who tf even invented copy pasting?

polar aspen
#

Hi anyone knows how to use same command and add arguments on it ?

frozen forum
#

I have fixed it

slate swan
#

i think the setup indent is a bit big

slate swan
#

and by a bit i mean a lot

polar aspen
#

And i want to use the command name multiple time but add different specific text

high flame
high flame
stark bobcat
boreal ravine
unkempt canyonBOT
#

Indentation

Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.

Example

def foo():
    bar = 'baz'  # indented one level
    if bar == 'baz':
        print('ham')  # indented two levels
    return bar  # indented one level

The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.

Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines

More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation

full valley
#

Guys what’s the best way to learn coding bots, I’ve seen heaps of tutorials for things like moderation bots and things but nothing that I am aiming to do.

valid perch
#

Learn python first. Then

#

!d discord

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.

full valley
#

I know python

#

and have setup a basic bot

stark bobcat
frozen forum
boreal ravine
#

i watched that video

valid perch
frozen forum
#

wait is it done ?

stark bobcat
boreal ravine
#

its cringy he doesnt even explain what the code does?

boreal ravine
stark bobcat
frozen forum
stark bobcat
boreal ravine
valid perch
#

Its defined in an else. So its only going to exist if a very specifc piece of ccode runs

stark bobcat
frozen forum
#

bro,...

valid perch
#

No offense, but the error says otherwise. Can you add some print statements after where you define it?

boreal ravine
stark bobcat
#

ok

#

one min

boreal ravine
#

play music first

#

then try to stop it

frozen forum
#

and an yt vid link

jade jolt
#

!ytdl

unkempt canyonBOT
#

Per Python Discord's Rule 5, we are unable to assist with questions related to youtube-dl, pytube, or other YouTube video downloaders as their usage violates YouTube's Terms of Service.

For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2021-03-17:

The following restrictions apply to your use of the Service. You are not allowed to:

1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service;  (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;

3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTube’s robots.txt file; (b) with YouTube’s prior written permission; or (c) as permitted by applicable law;

9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
frozen forum
#

ok

frozen forum
#

i sent ya server link

boreal ravine
#

no i cna ban u with that but im nice

boreal ravine
slate swan
#

:o now the new guy do be dm advertising

slate swan
jade jolt
#

me too

boreal ravine
atomic topaz
#

is there any way to get the list of all the channels names in a particular server? using discord.py

stark bobcat
#

@valid perch

frozen forum
stark bobcat
unkempt canyonBOT
valid perch
atomic topaz
slate swan
#

no

boreal ravine
#

do +join first??

frozen forum
stark bobcat
#

wai

boreal ravine
#

ofc it says nonetype has no attr play it isnt even in a vc lol

slate swan
stark bobcat
#

wai it works

slate swan
stark bobcat
#

but before i added the print statement it did not work

#

eh

slate swan
frozen forum
stark bobcat
#

Thanks

boreal ravine
#

show code

frozen forum
boreal ravine
#

no

slate swan
boreal ravine
#

here

slate swan
#

Copy pasting thie exact code will get you an error

#

As per usual when people spoonfeed

boreal ravine
#

@frozen forum here

slate swan
#

And just help nobody

warm flame
#

why am i getting this error?

#

it says 'unresolved reference'

#

full code

atomic topaz
atomic topaz
slate swan
#

Use your python knowledge

slate swan
slate swan
warm flame
atomic topaz
full pulsar
warm flame
atomic topaz
#

should I do it like this? guild.channels

slate swan
slate swan
#

There's nothing more I can explain

atomic topaz
slate swan
#

It's pretty much self explaining

atomic topaz
atomic topaz
# slate swan It's pretty much self explaining

I'm getting a list like this

[<TextChannel id=889528021076283424 name='other-servers-you-should-check-out' position=5 nsfw=False news=False category_id=891448181433466931>, <TextChannel id=891786097858854993 name='giveaway-payout' position=6 nsfw=False news=False category_id=891448181433466931>, <TextChannel id=893273251285970954 name='shop-and-trading' position=7 nsfw=False news=False category_id=891448181433466931>, <TextChannel id=891506761847148544 name='poke-show-off-january' position=8 nsfw=False news=False category_id=891506620494921739>, <TextChannel id=891506852205043722 name='undertale-show-off-febuary' position=9 nsfw=False news=False category_id=891506620494921739>]

is there any way to fetch that name of each channel?

slate swan
#

Iterate through all the elements in the list and get the .name attribute of each of these

atomic topaz
#

oh

#

okay

atomic topaz
slate swan
#

:)

rapid pebble
#

O wait they already answered that lol

warm flame
#

how can i get rid of this error?

#

im only giving 1 arguement

agile goblet
#

pass self

slate swan
#

Or Remove self from get_bank_data

warm flame
#

it gives more errors

slate swan
#

It's not required there

agile goblet
#

yeah its technically not required

hasty iron
#

what?

agile goblet
#

wait no its in a class innit

hasty iron
#

its inside a class

agile goblet
#

im blind

hasty iron
#

it has to have self, unless you make it a staticmethod

#

or a classmethod

agile goblet
#

whats line 25

hasty iron
#

but classmethods usually have cls as their first arg

warm flame
hasty iron
#

did you make sure to reload your code

#

also users will be a coroutine object in your code

#

and there is no reason to make get_bank_data an async function

#

and im sure open_account doesn’t have to be async too

warm flame
#

ok

#

but that doesnt fix the issue

hasty iron
#

i know it doesn’t

#

im telling you its useless to make it an async function

warm flame
#

but i need to fix the issue atm

stark bobcat
#

how do i check if a command is invoked

warm flame
#

print("invoked")

#

on the command function