#discord-bots

1 messages · Page 542 of 1

slate swan
#

with me i always get kicked

#

and get a error msg

boreal ravine
#

you can set a profile to webhooks

#

theres literally a kwarg for that

#

!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.
lusty swallow
#

ooooh thanks

#

!d discord.ext.commands.when_mentioned_or lol i found it

unkempt canyonBOT
#

discord.ext.commands.when_mentioned_or(*prefixes)```
A callable that implements when mentioned or other prefixes provided.

These are meant to be passed into the [`Bot.command_prefix`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.command_prefix "discord.ext.commands.Bot.command_prefix") attribute.

Example

```py
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'))
```...
lusty swallow
#

nvm yeah it was a webhook. In mobile it looked like a profile but now that i'm on my pc, it definitely is a webhook

boreal ravine
#

hm

slate swan
#
music = discord.utils.get(client.voice_clients, guild=ctx.guild)
        channel = ctx.author.voice.channel

        if not music.is_connected():
            await channel.connect()
``` Why does that not working? `Command raised an exception: AttributeError: 'NoneType' object has no attribute 'is_connected'`
glad sleet
#

what error consol also run ?

glad sleet
slate swan
#

No, I want to check for it with that

errant shuttle
#

Hey, what is the code to fetch a role in nextcord?

neon spear
#

Why isn't this if statement working

async def dm(ctx):
    for file in filenameArray:
        file = file.replace(".png","")
        if(ctx.author.id == file):
            await ctx.author.send(url)
slate swan
boreal ravine
#

hm

boreal ravine
unkempt canyonBOT
#
Out of the question.

No documentation found for the requested symbol.

boreal ravine
#

uh oh

umbral carbon
#

hey i was making an economy bot and im pretty new to this so im learning and writing the code altogether, but it doesnt seem to work can someone help?

boreal ravine
#

i mean sure

umbral carbon
#

how do i use the pastebin thing

coarse iris
#

Hi, I was wondering if it's possible to purge messages just by id alone. I've been trying to rack my brain but nothing is coming up, does anyone have any idea?

umbral carbon
#

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

umbral carbon
#

can someone tell me if you can spot any mistake in my code

final pawn
boreal ravine
#

!code

unkempt canyonBOT
#

Here's how to format Python code on Discord:

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

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

slate swan
#
    if ctx.author.voice:

        music = discord.utils.get(client.voice_clients, guild=ctx.guild)
        channel = ctx.author.voice.channel

#       if not music.is_connected():     if ctx.guild.me.voice is None:
            await channel.connect()

        if ctx.author.voice.channel == ctx.guild.me.voice.channel:

            if music.is_playing():
                music.stop()
```Both ifs aren't working....
boreal ravine
umbral carbon
#

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

umbral carbon
#

this is the error

boreal ravine
#

@umbral carbon put {} in the json file

umbral carbon
#

i did

final pawn
umbral carbon
#

the curly braces get deleted when i run the command tho

#

why?

boreal ravine
#

hm

#

ok

grand anvil
#

guys I got a sick idea for a game bot! not sure how long it'll take to make it but I think its worth making

umbral carbon
#

what is it

grand anvil
umbral carbon
#

oh yeah

#

nvm

grand anvil
#

its not exactly easy to just make it but someone good might be able to pull it off

umbral carbon
#

im someone bad

grand anvil
#

lol

#

I mapped out whole process about how I would make it work

#

but I don't have time to make it happen soon 💀

#

BTW how do you guys increase the reach of your bot initially?

umbral carbon
#

friends

#

advertising

grand anvil
umbral carbon
#

your friends have friends

grand anvil
#

well honestly only 2 of my friends own servers that I know of

#

and I was the og owner of one of those

umbral carbon
#

even if you get it into 1 big serveer

grand anvil
#

its pretty decent at 2.6k members rn

umbral carbon
#

it might pop off

coarse iris
#

Hi, I was wondering if it's possible to purge messages just by id alone. I've been trying to rack my brain but nothing is coming up, does anyone have any idea?

umbral carbon
#

wdym just by id?

grand anvil
umbral carbon
#

maybe

grand anvil
#

hmm

grand anvil
coarse iris
grand anvil
#

tho I have no irl friends on discord who r active now. I will have to depend on online friends

umbral carbon
coarse iris
umbral carbon
#

ohh

#

idk how to do that sorry lol

boreal ravine
#

lambda check

#

!d discord.TextChannel.purge

coarse iris
#

It's Oki and idk how to do that

unkempt canyonBOT
#

await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Purges a list of messages that meet the criteria given by the predicate `check`. If a `check` is not provided then all messages are deleted without discrimination.

You must have the [`manage_messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_messages "discord.Permissions.manage_messages") permission to delete messages even if they are your own. The [`read_message_history`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.read_message_history "discord.Permissions.read_message_history") permission is also needed to retrieve message history.

Examples

Deleting bot’s messages...
umbral carbon
coarse iris
slate swan
hollow mortar
#

hello i have a question do i can make a discord bot that can kick all ppl in the server ?

umbral carbon
boreal ravine
umbral carbon
#

nope

slate swan
umbral carbon
#

it deleted teh curly when i ran the command and idk if thats intentional

hollow mortar
#

any help ?

hollow mortar
#

yes i think it might work if i use a loop

slate swan
grand anvil
umbral carbon
#

tell me if you guys know anything

coarse iris
slate swan
#

fixed it

coarse iris
#

tysm

valid niche
unkempt canyonBOT
#

When using JSON, you might run into the following error:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

This error could have appeared because you just created the JSON file and there is nothing in it at the moment.

Whilst having empty data is no problem, the file itself may never be completely empty.

You most likely wanted to structure your JSON as a dictionary. To do this, edit your empty JSON file so that it instead contains {}.

Different data types are also supported. If you wish to read more on these, please refer to this article.

grand anvil
#

💀

boreal ravine
#

Lmao

grand anvil
#

bruh I don't think we're supposed to help with nukes here

#

lmao

boreal ravine
#

lmAo

hollow mortar
#

he shouldnt play with a developer

valid niche
#

<@&831776746206265384>

hollow mortar
#

what ?

grand anvil
#

@hollow mortar it wasn't a good idea to ask that here bro

hasty iron
#

you probably shouldn’t have pinged mods

hollow mortar
grand anvil
#

should've gone to google instead

umbral carbon
hasty iron
#

it’s a better idea to dm modmail

dapper cobalt
#

!rule 5

unkempt canyonBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.

boreal ravine
#

define user

hollow mortar
#

bro chill

grand anvil
#

you haven't defined user

hollow mortar
#

stop mods or anything it was just a joke mnan

valid niche
hollow mortar
#

got everything removed man chilllllllllll

coarse iris
slate swan
#

it does

coarse iris
#

i must be using it wrong

hollow mortar
slate swan
#

show how you're using it

hasty iron
#

no

grand anvil
#
@client.command(aliases=['boosterlist'])
@commands.cooldown(4,15, commands.BucketType.guild)
async def boosters(ctx):
    list = ctx.guild.premium_subscribers
    boosters = ""
    count = 0

    if len(list) > 0:
        for boosters in list:
            boosters.name

            count += 1
            boosters += f"\n`{count}` {booster.name}#{booster.discriminator}  `({booster.id})`"
    for user in list:
        embed = discord.Embed(title=f":boost: {ctx.guild.name}'s boosters" ,description=boosters ,color=0xd40000)
        await ctx.send(embed=embed)
#

@potent jetty

#

wait nvm

#

lemme edit it

coarse iris
grand anvil
#

you're trying to get a list of boosters and no. of boosters right?

slate swan
grand anvil
#

ok wait

coarse iris
# slate swan and in your code?
@commands.command()
    @commands.has_role('Mod')
    async def clear(self, ctx, amount : int):
        channel = ctx.channel
        await channel.purge(limit=amount, check=lambda m: m.author.id == user_id) 
        Embed=discord.Embed(title=f":white_check_mark: | Deleted {amount} messages", color=0x228B22, timestamp=ctx.message.created_at)
        await ctx.send(embed=Embed, delete_after=10)```
slate swan
#

!codeblock

unkempt canyonBOT
#

Here's how to format Python code on Discord:

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

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

valid niche
slate swan
#

put your code in a codeblock

coarse iris
umbral carbon
grand anvil
#
@client.command(aliases=['boosterlist'])
@commands.cooldown(4,15, commands.BucketType.guild)
async def boosters(ctx):
    booster_list = ctx.guild.premium_subscribers
    boosters = ""
    count = 0

    if len(booster_list) > 0:
        for booster in booster_list:

            count += 1
            boosters += f"\n`{count}` {booster.name}#{booster.discriminator}  `({booster.id})`"
    embed = discord.Embed(title=f":boost: {ctx.guild.name}'s boosters" ,description=boosters ,color=0xd40000)
    await ctx.send(embed=embed)```
#

@potent jetty

coarse iris
grand anvil
#

I hope there is no error in this 😩

slate swan
#

in your params

#

you haven't defined user_id

#

anywhere

slate swan
grand anvil
hasty iron
#

and you can just do if booster_list:

slate swan
#

yeah

hasty iron
#

and im pretty sure you can make enumerate start at 1

#

so you wouldn’t have to increment

grand anvil
grand anvil
#

np :D

hasty iron
#

!d enumerate

unkempt canyonBOT
#

enumerate(iterable, start=0)```
Return an enumerate object. *iterable* must be a sequence, an [iterator](https://docs.python.org/3/glossary.html#term-iterator), or some other object which supports iteration. The [`__next__()`](https://docs.python.org/3/library/stdtypes.html#iterator.__next__ "iterator.__next__") method of the iterator returned by [`enumerate()`](https://docs.python.org/3/library/functions.html#enumerate "enumerate") returns a tuple containing a count (from *start* which defaults to 0) and the values obtained from iterating over *iterable*.

```py
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
```  Equivalent to...
grand anvil
slate swan
hasty iron
#

read what it says

slate swan
#

!e ```py
letters = ['a', 'b']

for index, letter in enumerate(letters):
print(f"index={index}\nletter={letter}")

unkempt canyonBOT
#

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

001 | index=0
002 | letter=a
003 | index=1
004 | letter=b
grand anvil
coarse iris
#

@slate swanso this? py @commands.command() @commands.has_role('Mod') async def clear(self, ctx, amount : int, user: discord.Member = None): channel = ctx.channel await channel.purge(limit=amount, check=lambda m: m.author.id == user_id) Embed=discord.Embed(title=f"✅ | Deleted {amount} messages", color=0x228B22, timestamp=ctx.message.created_at) await ctx.send(embed=Embed, delete_after=10)

slate swan
hasty iron
slate swan
#
import discord
import time
wait=time.sleep
client=discord.Client()
@client.event
async def on_message(message):
    if 'hello' in str.lower(message.content):
        await message.channel.send('Hello!')

client.run('lol u thought')
```why does my bot spam "Hello!"
hasty iron
#

it by itself doesn’t return a tuple

grand anvil
slate swan
slate swan
#

why not

hasty iron
slate swan
#

str.lower(message.content)

#

oh

hasty iron
slate swan
#

how come

midnight chasm
#

how do i fix this message?

hasty iron
#

you just shouldn’t do it

slate swan
#

oh damn how would i check

#

what is str

coarse iris
slate swan
hasty iron
#

!e

print(str.lower("HelO"))
unkempt canyonBOT
#

@hasty iron :white_check_mark: Your eval job has completed with return code 0.

helo
slate swan
#

so user_id is undefined

hasty iron
grand anvil
midnight chasm
slate swan
#

!e print(str.lower("REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"))

dapper cobalt
grand anvil
slate swan
#

!e print(str.upper("hello!"))

grand anvil
#

@slate swan I think this isn't the place to do this

polar coyote
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.

coarse iris
slate swan
slate swan
grand anvil
dapper cobalt
slate swan
#

it's like

midnight chasm
slate swan
#

discord.Guild in code

midnight chasm
#

import discord
import os
import requests
import json

client = discord.Client()

def get_quote():
response = requests.get('https://zenquotes.io/api/random')
json_data = json.load(response.text)
quote = json_data[0]['q'] + " –" + json_data[0]['a']
return(quote)

@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('$inspire'):
quote = get_quote()
await message.channel.send(quote)

hasty iron
dapper cobalt
polar coyote
slate swan
#

how is str not just a class

hasty iron
midnight chasm
hasty iron
#

it is a class?

slate swan
# grand anvil like the enumerate

for some_index_var, some_value_var in enumerate(iterable), some_index_var will start at 0 and as it loops through the iterable it will increase by 1

midnight chasm
#
import os
import requests
import json 

client = discord.Client()

def get_quote():
  response = requests.get('https://zenquotes.io/api/random')
  json_data = json.load(response.text)
  quote = json_data[0]['q'] + " –" + json_data[0]['a']
  return(quote)

@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return 

  if message.content.startswith('$inspire'):
    quote = get_quote()
    await message.channel.send(quote)```
slate swan
#

I'm just gonna shut up bru

grand anvil
slate swan
#

oh if you pass something in lower() it works like that

hasty iron
slate swan
#

didn't know that

grand anvil
hasty iron
#

but it isn’t recommended to do so

polar coyote
# midnight chasm ```import discord import os import requests import json client = discord.Clien...
import discord
import os
import requests

client = discord.Client()

def get_quote():
  response = requests.get('https://zenquotes.io/api/random%27')
  json_data = response.json()
  quote = json_data[0]['q'] + " –" + json_data[0]['a']
  return quote

@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return 

  if message.content.startswith('$inspire'):
    quote = get_quote()
    await message.channel.send(quote)
```try this
dapper cobalt
slate swan
#
import discord
import time
wait=time.sleep
client=discord.Client()
@client.event
async def on_message(message):
    if 'hello' in str.lower(message.content) and not message.author==client:
        await message.channel.send('Hello!')

```i tried
grand anvil
hasty iron
slate swan
#

well that didn't make it obvious

hasty iron
#

what

slate swan
#

is there a difference?

slate swan
#

I'm in a learning phase

dapper cobalt
slate swan
#

at the end

coarse iris
#

@slate swani put user_id py @commands.command() @commands.has_role('Mod') async def clear(self, ctx, amount : int, user_id : discord.Member = None): channel = ctx.channel await channel.purge(limit=amount, check=lambda m: m.author.id == user_id) Embed=discord.Embed(title=f"✅ | Deleted {amount} messages", color=0x228B22, timestamp=ctx.message.created_at) await ctx.send(embed=Embed, delete_after=10)

hasty iron
unkempt canyonBOT
#

@hasty iron :white_check_mark: Your eval job has completed with return code 0.

001 | AAA
002 | AAA
slate swan
#

no difference?

grand anvil
slate swan
hasty iron
grand anvil
#

oh now I understand his question

midnight chasm
#

e

grand anvil
slate swan
dapper cobalt
slate swan
hasty iron
midnight chasm
#

lmao

coarse iris
# slate swan typehint it to an `int` not a `discord.Member`

so like this? py @commands.command() @commands.has_role('Mod') async def clear(self, ctx, amount : int, user_id : int = None): channel = ctx.channel await channel.purge(limit=amount, check=lambda m: m.author.id == user_id) Embed=discord.Embed(title=f"✅ | Deleted {amount} messages", color=0x228B22, timestamp=ctx.message.created_at) await ctx.send(embed=Embed, delete_after=10)

slate swan
#

AY IT WORKS TY

dapper cobalt
slate swan
grand anvil
slate swan
#

like it's better like:
if hello is None:
instead of
if hello == None

dapper cobalt
slate swan
#

😂

coarse iris
grand anvil
slate swan
#

yw

grand anvil
#

well output is gonna be same

slate swan
slate swan
grand anvil
hasty iron
#

is is for comparing singletons

slate swan
#

I'm usually not here to get help it was just situational

slate swan
unkempt canyonBOT
#
Missing required argument

pep_number

slate swan
#

uh

grand anvil
#

epic

slate swan
#

^

#

like the situation before about str.lower

coarse iris
#

@slate swan, it kinda worked?

slate swan
#

you should really do it yourself

#

i gave you a working example

coarse iris
#

tysm anyways

grand anvil
#

there is a difference you just need to understand it and idk how to explain it

slate swan
#

you're making me crazy

hasty iron
#

you can change how == works for objects but you cant for is

slate swan
#

asks what pep rules is
explains pep

hasty iron
grand anvil
#

those are 2 fundamentally different things

hasty iron
#

it’s just uh.. python?

grand anvil
#

lmao ig

#

if you dig deeper, python is complex

slate swan
#

oh wait what

grand anvil
#

and I'm not even a pro

grand anvil
#

they just give same output in certain scenarios

#

I was telling that

vale moon
#

can anyone send me the scrit of turning the bot online

slate swan
#

nah I'm gonna learn c# I'm out

grand anvil
#

but then you would say:

a = "hi"
b = "hi"
print(a is b)``` should also return False but it will return True
#

its just you gotta understand it deeper

grand anvil
vale moon
#

tru

grand anvil
hasty iron
#

!e ```py
class Object:
instance = None
def new(cls):
if cls.instance:
return cls.instance
cls.instance = super().new(cls)
return cls.instance

obj1 = Object()
obj2 = Object()
print(obj1 is obj2)

unkempt canyonBOT
#

@hasty iron :white_check_mark: Your eval job has completed with return code 0.

True
grand anvil
vale moon
grand anvil
#

my CS teacher taught me

grand anvil
#

channel died. Nice

vale moon
#

lol

slate swan
#

!e

list1 = []
list2 = []
list3=list1
 
if (list1 == list2):
    print("True")
else:
    print("False")
 
if (list1 is list2):
    print("True")
else:
    print("False")
 
if (list1 is list3):
    print("True")
else:   
    print("False")
 
list3 = list3 + list2
 
if (list1 is list3):
    print("True")
else:   
    print("False")
unkempt canyonBOT
#

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

001 | True
002 | False
003 | True
004 | False
hollow mortar
#

hello any idea how i can make this work with id

slate swan
#

hm

hollow mortar
#
    await message.channel.purge(limit=)```
slate swan
#

you mean with the channel's id?

hollow mortar
#

this code it remove msg from the channel that the msg sent in i want to make it remove msg from the channel id that i gave to the bot

#

yessir

slate swan
#

bot.get_channel(id)

#

returns the channel

#

just like message.channel returns one

hollow mortar
#

i have this

slate swan
#

so you can replace message.channel with bot.get_channel(id)

hollow mortar
#
member_channel = bot.get_channel(886784755083907082)
await message.channel.purge(limit=)```
slate swan
#

this would also work if you replace message.channel with member_channel

hollow mortar
#

yup thanks i will test it out then

slate swan
#

and pass something in limit

hollow mortar
#

yup i know thanks alot

slate swan
#

yw

hollow mortar
#

i got this problem

#
discord.ext.commands.errors.MissingRequiredArgument: message is a required argument that is missing.```
slate swan
#

send the whole command

#

how to install PIL

midnight chasm
#
import os
import requests
import json

client = discord.Client()

def get_quote():
  response = requests.get('https://zenquotes.io/api/random')
  json_data = response.json()
  quote = json_data[0]['q'] + " –" + json_data[0]['a']
  return quote

@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return 

  if message.content.startswith('$inspire'):
    quote = get_quote()
    await message.channel.send(quote)```
slate swan
#

wrong chat sorry

brave vessel
slate swan
#

bruh what's with the ᓚᘏᗢ gang

brave vessel
#

.catify muhaha

slate swan
#

that's a thing??

#

it's not

#

wait nvm i'm dumb 🤦‍♂️

#

hehe

slate swan
#

there i'm in 😎

#

lesgo

slate swan
#

no

#

😳 😳

somber musk
#

Can a discord bots code have 2 languages for example js and py and both parts of the code will work?

valid niche
#

Which is currently never done so you’d be making a massive breakthrough in technology if you pull it off

slate swan
#

lmao

#

how can i make bot respond to mention i have tried if client.user.mentioned_in(message): but if someone pings everyone bot responds too.

covert igloo
valid niche
#

The correct way would be to set the prefix, but seeing as you’re using a client and not a bot you don’t have access to a prefix

#

I recommend you switch over to the commands ext as it allows you to set commands easier and more cleanly

#

It also included tons of extra functions

#

Just replace client = discord.Client() with bot = commands.Bot(command_prefix=“prefix here”)

#

Make sure to add an import from discord.ext import commands

#

And replace all instances of client with bot

slate swan
#

is bad

valid niche
#

It’s not bad

slate swan
valid niche
#

But it’s what you’re using now

#

You should switch to commands.Bot

final iron
valid niche
slate swan
valid niche
#

According to naming conventions, you are using client and not bot

slate swan
final iron
#

Naming does not matter in this case

valid niche
#

Naming is very important

slate swan
final iron
valid niche
#

Always, it’s always important

#

Someone who looks at your code needs to see in the blink of an eye what a variable means

final iron
#

It does not matter if you call your commands.Bot instance client in this case

valid niche
#

If you call your Bot client you are not doing that

slate swan
final iron
#

But it doesn't matter

final iron
valid niche
#

If you share a snippet of code like you did now which did not include the line I assumed you used discord.Client

#

Even tho you are using bot

#

See why naming is important?

final iron
#

You're the only one who does that though

#

Look in this channel

#

People name it client but people understand they're using commands.Bot

#

That's just how it is

valid niche
#

Me and many others have been trying to remove this bad habit from everyone

#

It’s a bad habit, it’s bad naming. The most essential thing with programming is making code that you and anyone with a slight bit of knowledge can understand

#

And not have to guess

final iron
#

Can you show me the other people who have been doing this?

valid niche
#

Look at their website

final iron
#

So one person

valid niche
#

You asked for one example

#

I give you one example

slate swan
#

Count me in as well

kindred epoch
final iron
#

Can I have multiple examples?

vocal plover
#

pep8 mentions about good naming

slate swan
#

Naming your .Bot client is just plain stupid and confusing for whoever is reading your code

hasty iron
#

it’s not really stupid

valid niche
#

I’m sure @maiden fable is on this too

valid niche
slate swan
vocal magnet
#

!zen 6

unkempt canyonBOT
#
The Zen of Python (line 6):

Readability counts.

slate swan
#

Thank you 🙏

final iron
valid niche
slate swan
#

Me neither

valid niche
hasty iron
hasty iron
#

yes not always

final iron
hasty iron
#

but does Bot add something new like api calls?

slate swan
hasty iron
#

it doesn’t

valid niche
valid niche
final iron
valid niche
#

List is not exhaustive

#

Me kratos alex hunter chris are the 5 we listed just now

hasty iron
slate swan
hasty iron
#

you can check if the bot is mentioned with either

final iron
vocal magnet
slate swan
#

^

vocal magnet
#

Do what you want, but drop the subject here, since you're just wasting time now

#

arguing for the sake of argument

hasty iron
#

discord.Bot, shitpycord vibes

slate swan
#

😂

vocal magnet
#

lol

reef shell
#

xd

slate swan
#

this channel is hilarious, like, i dont even need to go to the circus, the circus is right here! yall guys madlads, arguments like are what keep me alive everyday

cursive crown
#

ok then 😆

#

does anyone know if the requests module can be used to edit discord messages?

slate swan
#

Why would you wanna do that using requests and not a discord wrapper for python

#

Like dpy

vestal owl
#

how can I remove roles from a user whenever a textchannel is deleted?

channel_srch = discord.utils.get(ctx.guild.channels, name = new_channel_name)```
this is what I have so far
midnight chasm
#

@client.command
@commands.has_permissions(kick_members=True)
async def kick(ctx, member : discord.member, *, reason=None):
  await member.kick(reason=reason)
  await ctx.send(f"{user} Has been kicked!")

@client.command
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.member, *, reason=None):
  await member.ban(reason=reason)
  await ctx.send(f"{user} Has been banned!")```
midnight chasm
lapis cedar
#

anyone know what why this script is giving me a type error?

cloud dawn
lapis cedar
#

ohhh

midnight chasm
# lapis cedar anyone know what why this script is giving me a type error?

you watchinghttps://www.youtube.com/watch?v=SPTfmiYiuok

Learn how to code a Discord bot using Python and host it for free in the cloud using Repl.it.
🚨Note: At 16:43, Replit now has a new method for environment variables. Check the docs: https://docs.replit.com/programming-ide/storing-sensitive-information-environment-variables

Along the way, you will learn to use Repl.it's built-in database and cr...

▶ Play video
slate swan
#
discord\client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\david\Desktop\dooby do\sust.py", line 15, in on_message
    member=str.split(message.content,' ')[2]
IndexError: list index out of range
```why is this happening
cloud dawn
lapis cedar
#

oh is it?

#

damn

#

any other suggestions then?

cloud dawn
#

Let's just say there are better one but it's not the worst.

midnight chasm
#

lmao ye

slate swan
#

wym

kindred epoch
midnight chasm
#

nope

kindred epoch
#

how

midnight chasm
#

"but it ain't the greatest"

kindred epoch
#

yea how

cloud dawn
whole sparrow
#

How do I run a tkinter GUI simultaneously while running the discord bot?

kindred epoch
#

everything in that turotial is outdated and not good

#

hosting using repl.it and that site that pings it

vestal owl
# slate swan wym
message = str(message.content)
message = message.split(' ')
member = message[2]```
midnight chasm
kindred epoch
cursive crown
#

what would you recommend besides using repl and pinging with uptimerobot?

cloud dawn
whole sparrow
midnight chasm
cloud dawn
#

If you got a credit card though, not pretty common in the EU

vestal owl
#
channel_srch = discord.utils.get(ctx.guild.channels, name = new_channel_name)
    member = ctx.guild.members
    if channel_srch == None:
        await member.remove_roles(role)```
How do I make a system that removes roles from a user once a text channel is deleted?
kindred epoch
#

lmfao

cloud dawn
kindred epoch
#

@midnight chasm no wonder you think that tutorial is good

lapis cedar
kindred epoch
#

your @client.command is missing () at the end

cloud dawn
#

Damn sasuke is on. 😂

final iron
cloud dawn
kindred epoch
midnight chasm
kindred epoch
midnight chasm
#

that's the thing

kindred epoch
#

what

lapis cedar
#

its a server box

kindred epoch
whole sparrow
#
async def tasks():
    await client.wait_until_ready()
    anotherfunc()
    gui.main_gui()

def main():
    client.loop.create_task(tasks())
    client.run(BOT_KEY)

How do I make it so I can run a gui alongside discord bot? It doesnt work as it runs the gui but does not load disc bot

cloud dawn
#

Wait isn't that just internet switch lol

kindred epoch
#

😂

final iron
#

Cool pycharm added "Tips of the day"

lapis cedar
kindred epoch
#

bruv

lapis cedar
#

like actually buy one

kindred epoch
#

here are all the vps we recommend

cloud dawn
#

Well a vps technically is just a pc.

kindred epoch
#

ye

midnight chasm
#

@kindred epoch no error with the ban/kick

final iron
#

Isn't a raspberry pi always an option

midnight chasm
#

i don't get it

cloud dawn
midnight chasm
#

bro....

final iron
kindred epoch
#

@midnight chasm can you also invite me to the server ur bot is in

cloud dawn
#

client gets defined twice aswell.

kindred epoch
#

so i can first kick some ppl and then ban

cloud dawn
kindred epoch
midnight chasm
#

like you though i wouldn't setup perms

kindred epoch
#

lmao i was joking, might just want to add some perm checks

final iron
#

Just use commands.Bot()

kindred epoch
#

^^

final iron
#

Just all around you shouldn't copy code

whole sparrow
#

Is there a way to run a gui simultaneously with discord bot? ive tried using tasks but it doesnt seem to work

kindred epoch
#

oo maybe he started with that video, thats why he not hating

midnight chasm
cloud dawn
final iron
kindred epoch
whole sparrow
midnight chasm
final iron
#

Thats good

midnight chasm
#

change discord.Client with commands.Bot()

cloud dawn
final iron
cloud dawn
#

just use this
bot = commands.Bot(command_prefix='.')

whole sparrow
#

that acc fixes so many problems

final iron
#

Is running a discord bot off a raspberry pi viable

#

I've never used one before

hasty iron
#

you wouldn’t need a subprocess if your gui lib supports async

whole sparrow
# cloud dawn Yep

If i knew this while doing another project bruh u dont understand my pain

#

i didnt know subprocessing was a thing oooof

cloud dawn
cloud dawn
#

You could prob run a discord bot on a usb stick.

hasty iron
whole sparrow
final iron
hasty iron
#

yes? ofc it is

cloud dawn
fallow mauve
#

im wanting to make it so when you use the help command it sends my bot's help message and reacts with an emoji, then if the user reacts with the same emoji it deletes it, can someone send me some working code for this? I've tried asking in here multiple times and tried a bunch to figure it out, ive looked for tutorials and i cant find anything. pls send me some to look at so i can learn how it works

cloud dawn
fallow mauve
#

thats not helpful

hasty iron
#

lmao

whole sparrow
#

💀

hasty iron
#

and to answer your question, no

fallow mauve
#

i need some code to break apart tho

hasty iron
#

code your own code

fallow mauve
#

i tried

#

why do you think im here?

whole sparrow
#

what have you got so far

fallow mauve
#

bcs it didnt work

hasty iron
#

and you expect us to just hand you code

#

that’s not help, that’s spoonfeeding

#

try it yourself, if you get stuck, ask for help here

#

don’t just give up and try to go the easy way

fallow mauve
midnight chasm
#

"how to get python code"

midnight chasm
hasty iron
#

you can keep sending your code and errors until you get useful help

cloud dawn
#

Most people here are all self taught...

fallow mauve
#

ill show you my code

fallow mauve
hasty iron
#

how many times

cloud dawn
#

Have you tried the docs?

fallow mauve
#

yes

#

ive tried everything people have told me

hasty iron
midnight chasm
#

just send ur code, we'il see what we can do

fallow mauve
#

also, it really seems like the only answers im getting are "go check the docs" or "try this, i have no idea if it will work or not"

hasty iron
#

dude just send your code and the errors you get

cloud dawn
hasty iron
#

bruh?

final iron
#

Looking at the code you've sent before

hasty iron
final iron
#

on_reaction_add only takes a reaction and user parameter not ctx

fallow mauve
#

mhm

#

i really wish someone would have told me that before, but everyone has told me to use it...

final iron
#

Nobody has told you to use it

cloud dawn
hasty iron
#

i wonder who is this "everyone"

fallow mauve
final iron
#

@fallow mauve

cloud dawn
unkempt canyonBOT
#

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

Waits for a WebSocket event to be dispatched.

This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.

The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.9)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.9)") for you in case of timeout and is provided for ease of use.

In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.9)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/master/api.html#discord-api-events) for a list of events and their parameters.

This function returns the **first event that meets the requirements**...
final iron
#

You were told it doesn't take a ctx parameter

fallow mauve
#

ok

#

nobody told me anything about fixing that

hasty iron
#

what

final iron
#

;-;

hasty iron
#

dude are you ignorant or what

cloud dawn
#

discord.ext.commands.Bot.wait_for if you want a time out, this is what i recommend.
discord.on_raw_reaction_add use this if you want the reaction to always stay there.

fallow mauve
final iron
#

Okay

#

Fix your code and see if there are any more errors

cloud dawn
fallow mauve
#

so what do i use instead of on_reaction_add?

final iron
cloud dawn
cloud dawn
hasty iron
hasty iron
whole sparrow
#
async def tasks():
    await client.wait_until_ready()
    ct.create_tables()

def main():
    subprocess.run("python utils/graphical_interface.py")
    client.loop.create_task(tasks())
    client.run(BOT_KEY)

the subprocess isnt running in parallel the client.run is still being held :C, howd u get ur website to run simultaneously

#

i might be very dumb rn

cloud dawn
hasty iron
#

uh

whole sparrow
#

asyncio has subprocess?

final iron
#

@fallow mauve Check the docs for wait_for it basically gives you what you need

whole sparrow
#

i thought subprocesses ran parallel by default

#

lemme try that

hasty iron
#

!d asyncio.create_subprocess_shell

unkempt canyonBOT
#

coroutine asyncio.create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None, limit=None, **kwds)```
Run the *cmd* shell command.

The *limit* argument sets the buffer limit for [`StreamReader`](https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamReader "asyncio.StreamReader") wrappers for `Process.stdout` and `Process.stderr` (if [`subprocess.PIPE`](https://docs.python.org/3/library/subprocess.html#subprocess.PIPE "subprocess.PIPE") is passed to *stdout* and *stderr* arguments).

Return a [`Process`](https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.asyncio.subprocess.Process "asyncio.asyncio.subprocess.Process") instance.

See the documentation of [`loop.subprocess_shell()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.subprocess_shell "asyncio.loop.subprocess_shell") for other parameters.

Important

It is the application’s responsibility to ensure that all whitespace and special characters are quoted appropriately to avoid [shell injection](https://en.wikipedia.org/wiki/Shell_injection#Shell_injection) vulnerabilities. The [`shlex.quote()`](https://docs.python.org/3/library/shlex.html#shlex.quote "shlex.quote") function can be used to properly escape whitespace and special shell characters in strings that are going to be used to construct shell commands.
cloud dawn
hasty iron
#

there it is

whole sparrow
#

o

#

alrighty

hasty iron
#

why are you even using subprocess

whole sparrow
#

omg it works

slate swan
#

Can anyone provide me an example of discord.py v2.0 button code? I am struggling with a button. I dont like it ;/

whole sparrow
#

its for school project, im doing something discord related but it must have a gui

hasty iron
#

does your gui lib support async?

cloud dawn
final iron
whole sparrow
hasty iron
hasty iron
whole sparrow
#

ty guys u made me save so much time love u

cloud dawn
hasty iron
#

but some methods inside can

#

if you use asyncio.create_subprocess_shell you can avoid that

cloud dawn
#

Hmm i will def use the asyncio version later.

final iron
#

Is there any documentation that was created for discord.Interactions specifically buttons?

cloud dawn
final iron
#

dpy discord?

cloud dawn
#

discord interactionss

final iron
#

interactions is in the dpy lib

hasty iron
#

dpy lib?

cloud dawn
final iron
hasty iron
#

do you mean the class or what

#

!d discord.Interaction

unkempt canyonBOT
#

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

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

New in version 2.0.
hasty iron
#

!d discord.on_interaction

unkempt canyonBOT
#

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

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

Warning

This is a low level function that is not generally meant to be used. If you are working with components, consider using the callbacks associated with the [`View`](https://discordpy.readthedocs.io/en/master/api.html#discord.ui.View "discord.ui.View") instead as it provides a nicer user experience.

New in version 2.0.
final iron
#

I meant documentation for buttons

hasty iron
#

!d discord.ui.View

unkempt canyonBOT
#

class discord.ui.View(*, timeout=180.0)```
Represents a UI view.

This object must be inherited to create a UI within Discord.

New in version 2.0.
final iron
#

Thank you

hasty iron
#

just read docs and you’ll find it

#

its under the discord.ui namespace

final iron
#

I was on the stable branch accidentally

slate swan
#
    from discord.ui import button, View, Button
    from discord.interactions import Interaction
    @client.command(aliases=["bj"])
    @commands.max_concurrency(1, per=BucketType.user, wait=False)
    @discord.ui.button(label='Confirm', style=discord.ButtonStyle.green)
    async def blackjack(ctx, coins):
        await Interaction.response.send_message(f'{coins}')

Error

AttributeError: 'CachedSlotProperty' object has no attribute 'send_message'
fallow mauve
#

ok i looked at the docs and i dont know whats not working here, theres no error at all it just wont delete it:

final iron
#

Why do you have an event inside a command?

fallow mauve
#

wow, a ping just for the word "um"

#

bcs i want it to work for that command only

hasty iron
#

that’s impressive, you were even given the docs of wait_for

final iron
#

^

hasty iron
#

oh man

#

you dont understand what an "example" is?

fallow mauve
#

yes i do

quiet coral
#

Hello, I wanna make a bot that announces who joined the voice channel any idea how to do it?

slate swan
hasty iron
#

it’s not advanced

#

and you’re supposed to know how to use classes and how subclassing works when using discord.py

fallow mauve
slate swan
#

but why go through classes and all that stuff, i want to have less lines of code for a button

hasty iron
#

because that’s how it’s done in dpy

slate swan
hasty iron
#

you could use a garbage third party lib

slate swan
#

exactly lol there is no difference, i dont get it

fallow mauve
hasty iron
#

nope there is a huge difference between an official implementation and a wannabe

slate swan
#

how is the unofficial worse than the official?

#

I want a way to use the buttons without having to create a class for it

hasty iron
#

have you seen or read some source code of those libs

slate swan
#

nope, but it works fine ;/

#

¯_(ツ)_/¯

slate swan
#

lol

#

is there no other way to use the official buttons without classes?

hasty iron
#

yeah

#

it saves you alot of effort

slate swan
#

;/

torn sail
#

can anyone help me with a problem i have with a command for my bot?

slate swan
#

im gonna stick with the poor mans way

lost lagoon
#

does anyone know how to get input from a user?

torn sail
lost lagoon
#

like if im making a quiz

#

and i need to know if they said a, b, or c

#

how would i check that

slate phoenix
unkempt canyonBOT
#

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

Waits for a WebSocket event to be dispatched.

This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.

The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.9)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.9)") for you in case of timeout and is provided for ease of use.

In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.9)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/master/api.html#discord-api-events) for a list of events and their parameters.

This function returns the **first event that meets the requirements**...
slate phoenix
#

then compare what they sent

lost lagoon
#

so reply = bot.wait_for

#

('message')

slate phoenix
#

make sure you have the check as well

torn sail
#

I have a problem with one of my commands. So i have a simple kick command. So when the bot joins the server it like gets its own role. When i add the kick members permissions to that role i get a Forbidden missing permissions error when i do the command. But when i add the admin role which has all the permissions the kick command works perfectly fine

lost lagoon
slate phoenix
#

well you need to have a check

lost lagoon
#

and when it says message do i have to say the right answer or just message?

hasty iron
#

await it

lost lagoon
#

await bot.wait_for?

slate phoenix
#

yep

lost lagoon
#

should i say 'a' or message

slate swan
#

hello every1

lost lagoon
#

hi there

slate swan
#

hows it going

lost lagoon
#

ok

#

im tryna figure out how to make a quiz

#

for my friends

lost lagoon
#

in message do i keep it as message or do i check the answer

#

and for check do i compare it to the right answer or what

slate swan
#

so there is a question and if some1 says the answer the bot will reply to the message and say its correct?

lost lagoon
#

its a social cred quiz

#

so idk what to do

kindred epoch
lost lagoon
#

so does reply = true of false

#

or is my current code correct?

lost lagoon
kindred epoch
#

Ur current code it correct

lost lagoon
#

Thanks

slate swan
#

this libs are actual trash, ama use the official, its actually easier

pliant gulch
#

Yea, don't even bother with extensions lmao

#

They implemented them very poorly, and it takes a lot of lines to send one dropdown lmao

#

Compare that to the one from discord.py its a lot more cumbersome

crisp hull
#

Yo Guys,
Is there a problem with having multiple events? Because it seems like my on_member_join event isn't working. The other one does. Can someone help?

@bot.event
async def on_member_join(member):
    guild = bot.get_guild(myIdIsHere)
    channel = guild.get_channel(myIdIsHere)
    print("It do be workin' tho!")
#

Like I don't get a print. Semms like the event doesn't work

rancid notch
crisp hull
slate swan
#
    class Counter(discord.ui.View):
        def __init__(self):
            super().__init__()
            self.number = 0
        @discord.ui.button(label='Press', style=discord.ButtonStyle.red)
        async def count(self, button: discord.ui.Button, interaction: discord.Interaction):
            self.number += 1
            await interaction.response.send_message(f"{self.number}")

how do i edit the message instead?

final iron
slate swan
#
    await interaction.response.edit_message(f"{self.number}")
TypeError: edit_message() takes 1 positional argument but 2 were given
cloud dawn
#

it takes kwargs

#

content=f"{self.number}"

gloomy quest
#

yo

#

i need help

slate swan
#

Go on

gloomy quest
#

i made a bot in repl

cloud dawn
gloomy quest
#

lol

slate swan
#

Without errors and code we can't guess what you need help for..

gloomy quest
#

can u take a look at it?

cloud dawn
#

i think indention error

hasty iron
#

name error

cloud dawn
#

Just send it xD

slate swan
#

module not found error

gloomy quest
#

ok i will send the link to the repl u will only have read access

slate swan
#

Share the code

hasty iron
#

no just send the code

slate swan
#

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

gloomy quest
#

ok

cloud dawn
slate swan
#

And what's your error

#

We won't read through your code trying to spot the error...

gloomy quest
#
@client.event
async def on_message(message):
  if message.author == client.users:
    await client.process_commands(message)
  role = client.users(822985879243980870)

  if role in client.users.role:
    msg = message.content.lower()
slate swan
#

Last command indentation is not correct

hasty iron
#

list is not a callable

#

and what even is that

slate swan
#

client.users 3HC_dudewhat

cloud dawn
slate swan
#

Yup

gloomy quest
#

im trying to make it so only someone with a certain role will be able to use word trigger

cloud dawn
#

Is this code from freecodecamp again?

gloomy quest
#

no

#

i made this with someone

#
@client.event
async def on_message(message):
  if message.author == client.users:
    await client.process_commands(message)
  role = message.guild.get_role(822985879243980870) 
  if role in message.author.roles:
    msg = message.content.lower()
#

should i put the name of the role as a string

cloud dawn
#

Sorry but i'm not going to help with an on_message command bot i recommend doing some more research first.

hasty iron
#

bruh

gloomy quest
#

is there something better than on message

hasty iron
#

what a reason to not help somebody

gloomy quest
#

the person who helped me make this is using old libraries

#

personally i dont like them but he's better than me so

shrewd pasture
#

does anyone know how to make all users that have the bot connected to their discord join a server? Example for what im saying:

#

"Join servers for you"

#

and then how to register when someone does that

cloud dawn
gloomy quest
#

lol

#

in other words i have no idead what im doing

shrewd pasture
#

mind sending an example

cloud dawn
gloomy quest
#

for me?

#

thx

cloud dawn
#

Yes, it's a pretty short tutorial but it will give you the general idea.

gloomy quest
#

thx

hasty iron
# shrewd pasture mind sending an example
Discord Developer Portal

Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.

Discord Developer Portal

Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.

gloomy quest
#

ok i have figured out that im doing wrong

#

i will make custom commands instead of word triggers

#

that will work better

cloud dawn
#

🥳

gloomy quest
#

thx for the link

#

it really helped

crisp hull
#

How can I get the clean_content from a string?

cloud dawn
unkempt canyonBOT
#

A property that returns the content in a “cleaned up” manner. This basically means that mentions are transformed into the way the client shows it. e.g. <#id> will transform into #name.

This will also transform @everyone and @here mentions into non-mentions.

Note

This does not affect markdown. If you want to escape or remove markdown then use utils.escape_markdown() or utils.remove_markdown() respectively, along with this function.

crisp hull
crisp hull
#

Thanks!!

swift field
#
@bot.command('join')
async def join(ctx):
    channel = ctx.author.voice.channel
    await channel.connect()

@bot.command('leave')
async def leave(ctx):
    await ctx.voice_client.disconnect()

Anyone know how to make an if statement where the conditional is if its connected to a channel....?

slate swan
#

is there a way to remove the button once i am done using it rather than just disabling it?

swift field
#

what

#

where...

#

If u mean the question i meant if the bot is connected to a channel

cloud dawn
#

I recommend printing ctx.author.voice.channel

#

See what result you get if it is in a voice channel and if it is not in a voice channel.

#

wait nvm you can't do that ugh lemme search it up

swift field
#

actually that might work

cloud dawn
#
async def is_connected(ctx):
    try:
        return ctx.guild.voice_client.channel
    except:
        return False
swift field
#

oh

cloud dawn
#
if await is_connected(ctx):
    ...
swift field
cloud dawn
pliant gulch
pliant gulch
swift field
cloud dawn
pliant gulch
#

Yes, the channel which the ctx author is in

cloud dawn
#

I think he wants to do it so people cannot move the bot around.

pliant gulch
#

To me it just seems like they want to check if the bot is in a channel before leaving or joining

#

Although not sure

pliant gulch
#

So then just do what I said

cloud dawn
#

Yep.

swift field
#

How do I do that....

pliant gulch
#

members is a property of voice channel, you access it via dotnotation or, getattr. Ex: Voicechannel.members. This returns a list of members. [member1, member2] you would check if ctx.me is inside of said list

#

You can do this with an in statement

#

!e ```py
list_of_members = [1, 2]

if 1 in list_of_members:
print("yes")

unkempt canyonBOT
#

@pliant gulch :white_check_mark: Your eval job has completed with return code 0.

yes
swift field
#

Oh ok I see

#

Welp

#

Thanks for the help

cloud dawn
#

Won't this also return an attribute error if the user executes the command whilst not inside a voice channel?

pliant gulch
#

👍

cloud dawn
#

True true.

pliant gulch
#

i.e if author.voice is not None: ...

cloud dawn
#

why not just if author.voice: ...

pliant gulch
#

Because voice can be None or a voice state

#

when checking for None you use is

cloud dawn
#

But a None type is false

pliant gulch
#

You can check if its truthy, sure but its a preference

gloomy quest
#

i want to restrict a word trigger

#

to a certain role

#
  if message.author.id == 872976347369201765:
    msg = message.content.lower()
#

ik the .authoir.id only looks for a specific user's id

#

but what can i do if i want to look for a role

slate swan
#
class shush:

    def delete(channel, message):
        r = requests.put(url=f"https://discord.com/api/v9/channels/{channel}/messages/{message}", headers=headers)
        if r.status_code == 200 or r.status_code == 201 or r.status_code == 204:
            print(f"{Fore.BLUE}>{Fore.RESET} Deleted {message}{Fore.RESET}")



@client.command()
async def massd(ctx):
    await ctx.message.delete()
    ids = open("ids.txt","r").read().splitlines()
    for message in ids:
        del = functools.partial(shush.delete, ctx.channel.id, message)
        threading.Thread(target=del).start()

im trying to make my bot delete messages with requests but it doesnt work and i get no errors any ideas?

visual island
#

del is a registered keyword on python

gloomy quest
#

yah

#

u have to do aliases=del

#

in the client command parantheses right?

final iron
final iron
forest vortex
#

@slate swan that line should be inside a function

winter meadow
#

How to check the number of messages a discord.py member sent?

I want to do a command that when a member sends a message (or a number of members) blocks the channel or channels to avoid spam.

valid perch
#

You could count them yourself

#

Alternately maybe a slow mode?

winter meadow
#

Is for help moderation

valid perch
#

Up to you how you handle it, slowmode on command, remove message perms

winter meadow
valid perch
#

Number of messages from 1 person right?

winter meadow
valid perch
#

Use a dictionary and in on message you can increase the counter

#

Then just reset it after x time or whatever

#

I might make a plugin for it on my package, seems like a nice idea tbh

winter meadow
#

Ok thanks

valid perch
#

Idk when imma make this plugin, but I can link you a place to wait for when I make my next release

winter meadow
#

Ok

maiden fable
void crane
#

Hi, does anyone know how to help me with this. I am trying to make my discord bot leave a vc but it isnt working.

maiden fable
#

Ghost ping

void crane
#

@client.command(pass_context=True)
async def leave(ctx):
if (ctx.voice_client):
await ctx.message.guild.voice_client.disconnect()
await ctx.send("I left the voice channel")
else:
await ctx.send("You need to be in a voice channel to do this")

slate swan
void crane
#

No, it send that it disconnected from the vc but it dosent leave

slate swan
#

also , pass_context is not longer required in the recent versions

void crane
#

kk

#

do i need pass_context for 3.9.6?

slate swan
#

depends on your discord.py version and not python version

void crane
#

kk

#

Yeah, but it says that it left the call but it stays in

slate swan
#

its weird that the bot does not disconnect since according to the code , it must disconnect first and send "I left the ... " message

#

did you rerun the code after saving?

void crane
#

yeah, i dont know why it just dosent work

#

It disconnects from the server but its because it times out

patent lark
#

!d discord.ext.commands.is_owner

unkempt canyonBOT
#

@discord.ext.commands.is_owner()```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that checks if the person invoking this command is the owner of the bot.

This is powered by [`Bot.is_owner()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.is_owner "discord.ext.commands.Bot.is_owner").

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

@commands.is_owner()

#

(for the person who asked but deleted their message)

void crane
#

Do i need to import something to make my discord bot leave a vc. I already have discord.py[voice]

graceful gorge
#

hello

unkempt canyonBOT
#

Hey @graceful gorge!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

graceful gorge
#

!code-block

unkempt canyonBOT
#

Here's how to format Python code on Discord:

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

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

valid perch
#

#bot-commands

covert igloo
#

i just opened my file and i randomly got that error

#

same with this

void crane
#

I am trying to make my discord leave a vc but it dosent leave it. Is there any obvious way to fix it that i didnt notce?

@client.command(pass_context=True)
async def leave(ctx):
if (ctx.voice_client):
await ctx.voice_client.disconnect()
await ctx.send("I left the voice channel")
else:
await ctx.send("You need to be in a voice channel to do this")

soft radish
#

how can i make reload cmd?

boreal ravine
boreal ravine
covert igloo
#

download what

boreal ravine
covert igloo
#

i didnt do anything to it, its been working ever since i started using it

boreal ravine
#

what does the error say

covert igloo
#

no module named ' discord.enums'

#

no model named 'discord.utils'

boreal ravine
#

did you download it though?

covert igloo
#

i dont remember

boreal ravine
#

bruh

covert igloo
#

its been working every since i started using it

#

and i didnt uninstall anything recently

soft radish