#discord-bots

1 messages · Page 633 of 1

brittle ingot
#

put a back slash in front of the emoji

slate swan
#

but where do i put in the code

brittle ingot
#

\

brittle ingot
cedar stream
prisma folio
slate swan
#

thx

brittle ingot
brittle ingot
#

yes

slate swan
#

but the command dosent wokr when i try to used i

brittle ingot
#

do you have an on_message event

#

well firstly are there any errors?

rare saddle
#

@cedar stream

slate swan
#

what intents are required to allow a bot to send users a dm

prisma folio
#

.

brittle ingot
#

try it. looks good to me

prisma folio
#

Awesome. Thanks! :).

slate swan
#

what intents are required to allow a bot to send users a dm

brittle ingot
#

thats it

slate swan
dire folio
#

whats is asyncio

slate swan
#

or

slate swan
manic wing
unkempt canyonBOT
pliant gulch
#

Don't use this package, this is for versions of python that don't have asyncio as a builtin

slate swan
#

em so @brittle ingot i send an screenshot with error

manic wing
brittle ingot
rare saddle
#

Why such a mistake?

pliant gulch
cedar stream
slate swan
cedar stream
manic wing
cedar stream
#

bot.get_guild

brittle ingot
cedar stream
#

Then get channel from that guild

manic wing
#

bot.version isnt a thing

rare saddle
slate swan
#

so how could i make it

brittle ingot
#

You can remedy this by creating a bot var named version with your bots current version.

slate swan
#

if i dont have access to the account that owns the bot (say the account was disabled), but my bots verified, how can i get its name changed

#

or can i not..

brittle ingot
#

I don’t think you can. As that happened to a bot dev with a huge bot “Eli” and they had to discontinue the bot

brittle ingot
# slate swan oh

In the bots main file right under the bot constructor put:

bot.version =“0.0.1”

Or whatever your version number is. Iirc

pliant gulch
#

Verified bot's cant even change their username

manic wing
#

ig not

pliant gulch
#

iirc, my friend who has a verified bot says discord doesn't allow them to change the bot's username after it gets verified

brittle ingot
#

Make sense, it’s like a branding thing

slate swan
silk mauve
#

colour=discord.Colour.()
How can I put there a colour code in?

pliant gulch
#

Yea you can't change the name after verifying

vale glen
#

Oof

manic wing
manic wing
#

!d discord.Colour || you would do color=discord.Coulor.red()

unkempt canyonBOT
#

class discord.Colour(value)```
Represents a Discord role colour. This class is similar to a (red, green, blue) [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.9)").

There is an alias for this called Color...
vale glen
#

or you could just do color=0xffffff

manic wing
#

fucking americans

silk mauve
#

ty

#

lol

manic wing
vale glen
manic wing
#

pls no ban

rare saddle
brittle ingot
#

Your doing the guild portion correctly. The issue is the channel ID. They are unique. Even if two servers have the same channel named “general” their IDs will be different. You need to change the portion where you are fetching the channel using the same ID every guild.

slate swan
brittle ingot
#

Errors will happen. It’s a normal part of programming. That’s why we are here 🙂

slate swan
vale glen
#

currently im using nextcord

dire folio
#

im getting the squiggly lines under all the ctx

manic wing
#

i just used ctx for the sake of the example

#

you can replace it with an instance of discord.Message if you want

dire folio
#

oh i have no clue what im doing tbh

vale glen
manic wing
unkempt canyonBOT
#
Resources

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

brittle ingot
# slate swan so what should i change in code

Right under:
bot = commands.Bot in your bots main file try adding
bot.version = “0.0.1”

That will create a bot variable if I remember correctly. You should be able to access it throughout your code using: bot.version

manic wing
vale glen
#

just waiting for a message?

manic wing
#

yes

vale glen
#

you explained it pretty well

dire folio
vale glen
vale glen
dire folio
brittle ingot
slate swan
vale glen
#

.content is just the message that is received

vale glen
brittle ingot
slate swan
#

oh

brittle ingot
#

Yeah just remove line 13. Also double check your imports looks like you are importing OS twice

brittle ingot
#

Also note for anyone imports can be done on one line.

#

Import discord, os, datetime, random, typing

jagged root
#

can a bot track messages of an embed

slate swan
manic wing
# slate swan

I think you copied what Moros wrote, and he's on mobile, so their "'s are different

jagged root
#

@manic wing

#

can a bot track messages of an embed

manic wing
brittle ingot
#

You mean embed content? Yes

lament trail
jagged root
manic wing
#

!d discord.Embed.to_dict

unkempt canyonBOT
jagged root
#

and then do something

vale glen
jagged root
#

theres a bot that sends embeds of the chat of a game so track if in those embeds theres a specific word
@lament trail

manic wing
lament trail
#

yea, assuming the words are in the 'description', (they can also be in the fields though) you can access the content using embed.description

jagged root
lament trail
#

yes

manic wing
jagged root
#

nicee

lament trail
#

its basically like reading messages but a couple extra steps

jagged root
#

can someone help me with that?

manic wing
#

!d discord.Message.embeds || you just need an instance of discord.Embed, which you can get from discord.Message.embeds

unkempt canyonBOT
manic wing
#

normally, its just discord.Mesage.embeds[0]

#

if there is only one embed

jagged root
#

ty mate ill try

jagged root
slate swan
#

is there a way to delete channels with a bot

brittle ingot
#

Just gotta figure out which part of the embed has the content you want to check for. Usually description.

brittle ingot
slate swan
brittle ingot
#

using the .delete() attribute on a discord.Channel object

manic wing
#

!d discord.TextChannel.delete

unkempt canyonBOT
#

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

Deletes the channel.

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

!d discord.VoiceChannel.delete

unkempt canyonBOT
#

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

Deletes the channel.

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

idk why i did this, im too tired to remember discord.Channel

brittle ingot
#

Lol

manic wing
#

oh its

#

I guess not pithink

brittle ingot
#

I’m so sad my computer broke

manic wing
brittle ingot
#

Iirc abc is usually for instances or conversion really

brittle ingot
manic wing
slate swan
#

the command works

manic wing
#

👏

brittle ingot
#

The bot version is a bit weird… but awesome that it works!!

slate swan
#

yeah

brittle ingot
slate swan
brittle ingot
#

What does the current code look like?

slate swan
#

wait

brittle ingot
#

Remove the brackets. Essentially make sure the the bot.version variable only contains a string of 0.0.1 so should look like:

bot.version = “0.0.1”

#

Don’t copy cause I’m on mobile

slate swan
#

ok

brittle ingot
#

Much better!

#

Good work

silk mauve
#

@bot.command()
@discord.ext.commands.has_role("Server Booster")
async def snipe(ctx):
if (not discord.ext.commands.has_role("Server Booster")):
await ctx.send('Du hast ein Booster Feature entdeckt!')
return
channel = ctx.channel
try:
snipeEmbed = discord.Embed(title=f"Letzte gelöschte Nachricht in #{channel.name}",
description=snipe_message_content[channel.id])
snipeEmbed.set_footer(text=f"Gelöscht von {snipe_message_author[channel.id]}")
await ctx.send(embed=snipeEmbed)
except:
await ctx.send(f"Es gibt keine gelöschten Nachrichten in #{channel.name}")

slate swan
#

so right now i need to add it in to my general bot not a testing bot

silk mauve
#

So, this is my code and I want that someones donesnt has the role that a message sends

#

who doesn't*

#
@discord.ext.commands.has_role("Server Booster")
async def snipe(ctx):
    if (not discord.ext.commands.has_role("Server Booster")):
     await ctx.send('Du hast ein Booster Feature entdeckt!')
    return
    channel = ctx.channel
    try:
        snipeEmbed = discord.Embed(title=f"Letzte gelöschte Nachricht in #{channel.name}",
                                   description=snipe_message_content[channel.id])
        snipeEmbed.set_footer(text=f"Gelöscht von {snipe_message_author[channel.id]}")
        await ctx.send(embed=snipeEmbed)
    except:
        await ctx.send(f"Es gibt keine gelöschten Nachrichten in #{channel.name}")```
slate swan
#

brackets in if statements 🤮

brittle ingot
#

A little bit of JS flair in there 🤣

silk mauve
#

Ok?

brittle ingot
#

The easiest way I could say would be to check within the command function instead of using a command check.

hollow agate
#
bot = slash_util.Bot(...)``` I'm trying to use the https://gist.github.com/XuaTheGrate/5690a3d9dadb280d3d15f28f940e02d1#installation library, what would I put in place for the 3 dots? I've never used cogs so this is all new haha
brittle ingot
#

role = discord.Utils.get(ctx.guild.roles, name=“Server Booster”)

If not role in ctx.author.roles:
Send failed message

else:
Continue

don’t copy I’m on mobile

summer flume
#

do buttons exist?

brittle ingot
#

Externally yes, in discord.py itself not that I’m aware of. You could get a lib like discord-components, etc

summer flume
#

okay

slate swan
#

but it's copiable

slate swan
#

i have an question why i getting owner as none in serverinfo command?

manic wing
slate swan
#

i think i need to check

#

in the code no but in the developer bot portal i turnd them on

manic wing
slate swan
#

ok

rare saddle
#

The message does not want to be sent, what should I do?

slate swan
#

this

#

how do you get the user of who created the bot?

hollow agate
#
class PersistentViewBot(slash_util.Bot):
    def __init__(self):
        super().__init__(command_prefix=commands.when_mentioned_or('/', '.', 'c.'), owner_id=503641822141349888, intents=intents)
        self.persistent_views_added = False

    async def on_ready(self):
        if not self.persistent_views_added:
            self.add_view(PersistentView())
            self.add_view(Ticket())
            self.add_view(TicketClose())
            self.add_view(AdminTicket())
            self.add_view(Verification())
            self.add_view(DropdownView())
            self.add_view(ForceTicketClose())
            self.add_view(HistoryView())
            self.add_view(DropdownView())
            self.persistent_views_added = True
            activity = discord.Game(name="fc.coolmcgames.xyz", type=3)
            await self.change_presence(status=discord.Status.online,
                                        activity=activity)

        print(f'Signed in as {self.user}')

bot = slash_util.Bot(command_prefix=commands.when_mentioned_or('/', '.', 'c.'), owner_id=503641822141349888, intents=intents)

class SlashCog(slash_util.ApplicationCog):
    def __init__(self, bot):
        super().__init__(bot)
        self.bot = bot

    @slash_util.slash_command()
    async def hello(self, ctx):
        await ctx.send('hi')

bot.add_cog(SlashCog(bot))``` How would I add the SlashCog bot to the PersistantViewBot? I'm trying to learn cogs and I'm stuck here on the documents haha.
slate swan
#
@bot.event
async def on_guild_join(ctx,guild : discord.Guild):
#stuff
  await ctx.send('thanks for the invite')
...
error:
TypeError: on_guild_join() missing 1 required positional argument: 'guild'
#

how can i introduce ctx as well as guild : discord.Guild to the event

#

without it seeing it as a required arg

manic wing
#

!d discord.on_guild_join || it only takes guild, not ctx.

unkempt canyonBOT
#

discord.on_guild_join(guild)```
Called when a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild") is either created by the [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") or when the [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") joins a guild.

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

so how would i get the bot to send a message to the top channel once it joins?

manic wing
slate swan
#

ok

manic wing
slate swan
slate swan
# manic wing intents.all()

import discord
from discord.ext import commands
from discord.ext import commands, tasks
import asyncio
from itertools import cycle
import os
import json
import random
import datetime
import requests
import aiosqlite
from typing import Text
import aiohttp
import platform
from discord.ext.commands import clean_content
intents = discord.Intents.default()
intents.members = True
intents.all() like this?

slate swan
manic wing
slate swan
#

but still it showing owner as a none

manic wing
brittle ingot
#

!intents

unkempt canyonBOT
#

Using intents in discord.py

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

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

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

from discord import Intents
from discord.ext import commands

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

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

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

slate swan
#

but i need to get owner as like @slate swan not as a none

#

400 Bad Request (error code: 50007): Cannot send messages to this user do we need intents to dm users?

manic wing
slate swan
slate swan
manic wing
manic wing
slate swan
#

ive tested this on a bot without verification and with all intents enabled (it worked perfectly fine) but now im testing it on a bot thats verified with to my knowledge no intents enabled, and it just wont continue if the suer cant be dmed

slate swan
manic wing
#

slate swan
# manic wing you caught the wrong exception then
@bot.event
async def on_guild_join(guild : discord.Guild):
    members = guild.members
    for member in members:
        try:
#embed stuff
            await member.send(embed=embed)
            print(f'dmed {member.name}#{member.discriminator}')
        except Exception as e:
            print(e)``` i was given authorization by the server owner to do this, servers very small
slate swan
#

but is still the same

#

error

slate swan
#

its in a loop, not sure why it doesnt continue if it finds a user that cant be dmed

slate swan
manic wing
slate swan
#

can i add ctx when subclassing help command? like async def send_bot_help(self, ctx, mapping):?

slate swan
manic wing
slate swan
#

i did

#

i can give u screen shot

#

spacing pepeugh

manic wing
# slate swan

you need to remove the intents = Intents.default() above

slate swan
# slate swan

change intents = discord.Intents.default() to intents = discord.Intents.sll()

manic wing
#

and the intents.members

slate swan
#

its so simple and we have told u multiple times

#

-_-

wild oak
#

@slate swan are you able to help me at the moment

slate swan
wild oak
#

apparently not he's muted

manic wing
wild oak
#

Bro im having so much trouble making the dumbest cog ever

#

i havent tested yet but i know it wont work

manic wing
# wild oak

you need to unindent def setup outside if the class

#

and the @commands.group needs to be indented inside

slate swan
#

Traceback (most recent call last):
File "C:\Users\PC\Desktop\Dadudeł Bot\Dadudeł Bot.py", line 17, in <module>
intenes.members = True
NameError: name 'intenes' is not defined wth

#

intens

hollow agate
#
class PersistentViewBot(slash_util.Bot):
    def __init__(self):
        super().__init__(command_prefix=commands.when_mentioned_or('/', '.', 'c.'), owner_id=503641822141349888, intents=intents)
        self.persistent_views_added = False

    async def on_ready(self):
        if not self.persistent_views_added:
            self.add_view(PersistentView())
            self.persistent_views_added = True
            activity = discord.Game(name="fc.coolmcgames.xyz", type=3)
            await self.change_presence(status=discord.Status.online,
                                        activity=activity)

        print(f'Signed in as {self.user}')

bot = slash_util.Bot(command_prefix=commands.when_mentioned_or('/', '.', 'c.'), owner_id=503641822141349888, intents=intents)

class SlashCog(slash_util.ApplicationCog):
    def __init__(self, bot):
        super().__init__(bot)
        self.bot = bot

    @slash_util.slash_command()
    async def hello(self, ctx):
        await ctx.send('hi')

bot.add_cog(SlashCog(bot))``` I can't seem to figure out how to add the cog to the PersistantViewBot, could someone help me with this?
manic wing
vale glen
#

Can you use hyperlinks inside of a embed title

manic wing
#

please read the error carefully

vale glen
#

Oh ok

slate swan
wild oak
#

omg

manic wing
# vale glen Can you use hyperlinks inside of a embed title

From R.Danny;

"[Text To Click](https://www.youtube.com/ \"Hovertext\")"

  • Needs to be a full url (http/https)
  • Hovertext is optional
  • If sent by a bot/user it needs to be in an embed
  • If sent in a webhook you can hyperlink raw text cuz fuck being consistent amirite discord
  • This only works in the embed description and field value
    If you want to hyperlink a title or set_author, you can use the url kwarg
wild oak
#

im sorry gimme a sec

rare saddle
#

Why does not add the participant to the database specifically to the blacklist

manic wing
vale glen
#

i forgot how to do the hovertext, thanks for showing me

wild oak
#

@manic wingU ARE A LITERAL WIZARD

wild oak
#

@manic wing Did i indent everything right

#

Darnit

rare saddle
#

How to make a check that if a person's id is in this key then ...

wild oak
#

what

wild oak
rare saddle
wild oak
#

whatttt

#

one sec lemme find a ss

rare saddle
#

I do not know what is chromebook.

wild oak
#

Bro Look my message i was looking for was above yours

rare saddle
wild oak
#

I used to code on a chromebook laptop

#

the stuff that looks like that

rare saddle
wild oak
#

nevermind just ignore it

#

Does anybody know how to fix this

slate swan
wild oak
#

my eyes

#

they burn

#

please help

slate swan
#

what?

wild oak
#

nothing its just its bright

#

do you know how to fix this??

slate swan
#

oh

#

Traceback (most recent call last):
File "C:\Users\PC\Desktop\Dadudeł Bot\Dadudeł Bot.py", line 17, in <module>
intents.all = True
AttributeError: 'Intents' object attribute 'all' is read-only i got something like that when i turned it on

wild oak
#

Does anyone know how to fix this

#

Please help

pulsar shell
#

Will my discord bot support sql injection if I use mongo db? @pliant gulch

brittle ingot
wild oak
#

but now its showing this

brittle ingot
#

Should be:

class myCog(commands.Cog):

carmine pilot
#

Can anyone tell me why my bot wont run the slash command on Visual Studio Code?


token = '1234567890'
bot = coammnds.Bot(
  intents=discord.Intents.all()
)

@bot.slash_command(
  name='ping', 
  description='Returns the bots latency.'
)
async def ping(ctx):
  embed = discord.Embed(
    color=color,
    title='**Ping**',
    description='\u200b'
  )
  await ctx.send(embed=embed)

bot.run(token)```
brittle ingot
#

Try to avoid naming commands and cogs the same thing. I’m assuming there is a naming conflict?

wild oak
#

Uhhh

#

Shoooooooot

#

ok just renamed it gimme a seccond

brittle ingot
#

Is spelled wrong

carmine pilot
#

.

wild oak
#

Nope

final iron
wild oak
#

Same thing

slate swan
#

import discord
from discord.ext import commands
from discord.ext import commands, tasks
import asyncio
from itertools import cycle
import os
import json
import random
import datetime
import requests
import aiosqlite
from typing import Text
import aiohttp
import platform
from discord.ext.commands import clean_content
intents = discord.Intents.all()
intents.all= True
bot = commands.Bot(command_prefix="+",intents=intents) what i did wrong?

wild oak
#

that keeps blinding me

brittle ingot
#

Remove intents.all = True

carmine pilot
final iron
#

Don't use it

brittle ingot
#

aiohttp

wild oak
#

still says the same thing :(

carmine pilot
final iron
slate swan
final iron
#

Just copy and paste

carmine pilot
#

Okay.

slate swan
#

ok

final iron
slate swan
#

i mean i need to test it

wild oak
#

im abt to just give up on this

slate swan
#

ooo it works but it didn't ping owner of the server

wild oak
slate swan
wild oak
#

i honestly have no clue how to fix this stupid thing

flint cosmos
#

Is there something I need to import for get_channel() , get_guild(), get_role(), etc ?

wild oak
#

literally

slate swan
wild oak
#

this close to giving up 🤏

#

what

#

i already tried to indent everything and then it had another problem idk what to do what part do u want me to indent

final iron
slate swan
#

indent the command decorator and the function

#
@client.event
async def on_message(message):
    if ('help' in message.content.lower() and 'staff' in message.content.lower()):
        await message.channel.send('Hello')
wild oak
#

like this

slate swan
#

Do I have to change message.send to something else?

wild oak
slate swan
#

no

#

?

#

add 4 spaces
not remove 4 spaces

#

me?

slate swan
wild oak
#

how would that magically fix it not being able to find the yoga ball command

#

and if it does istg im gonna flip out

slate swan
wild oak
#

oh my dilly darn gosh

#

i cant swear in this server lmao

final iron
slate swan
#

yes

final iron
#

There you go

wild oak
#

let me get this straight

#

you want me to indent this py class Ball(commands.Cog, name="Balls"): def __init__(self, bot): self.bot = bot

final iron
#

No

#

Indent the commands inside the class scope

slate swan
#

^^^

final iron
#

Also fix your indents inside of the commands

wild oak
#

im slow ur gonna have to gimme a break

slate swan
#

indent this part ```py
@commands.group(name = "yogaball")
async def yogaball(ctx):

wild oak
#

ok

slate swan
#

and the other one

wild oak
slate swan
#

yeah

#

now do the other one

wild oak
slate swan
#

yeah

#

wait

#

remove the context arg from the first one

wild oak
#

and put ctx

slate swan
#

you alr have ctx

wild oak
#

ok but now its gonna freak out

slate swan
#

why

wild oak
#

cuz it says

slate swan
#
@client.event
async def on_message(message):
    if ('help' in message.content.lower() and 'staff' in message.content.lower()):
        await message.channel.send('Hello')
slate swan
#

Does anyone know why. this event makes my bot stop responding to other commands?

#

process the commands

#

My bot literally stops working if i put this in

#

await client.process_commands(message)

#

at the end of your event

#

oh ok

wild oak
#

i was gonna say that

final iron
#

Use actual command decorators

wild oak
#

untill my pc decided to just stop functioning lmao

slate swan
final iron
slate swan
wild oak
#

isnt it outdated

#

@slate swan

slate swan
#

wat outdated

wild oak
#

context

#

or am i being slow

slate swan
#

the pass_context is outdated

carmine pilot
#

This code doesn't work on Python (vsc).

from discord.ext import commands

token = 'my_bot_token'
bot = commands.Bot(
  intents=discord.Intents.all()
)

@bot.slash_command(
  name='ping', 
  description='Returns the bots latency.'
)
async def ping(ctx):
  embed = discord.Embed(
    color=color,
    title='**Ping**',
    description='\u200b'
  )
  await ctx.send(embed=embed)

bot.run(token)
wild oak
#

ok

slate swan
slate swan
slate swan
#

And its an event?

final iron
final iron
slate swan
wild oak
#

thats great

#

now my help command doesnt work

#

LMAO

final iron
#

Lets see the code

slate swan
wild oak
#

i think i know the issue gimme a min

final iron
wild oak
#

()

final iron
#

Does dpy even support slash commands?

#

Wasn't that the reason danny quit?

final iron
slate swan
wild oak
#

omg i quit

final iron
wild oak
final iron
#

That is dpy

slate swan
#

py-cord is import discord

carmine pilot
final iron
#

!pypi py-cord

unkempt canyonBOT
wild oak
#

bro i thought it was cuz i didnt add like the info thing for it

final iron
wild oak
#

because my help command is setup like this

carmine pilot
wild oak
#

lmao

final iron
wild oak
#

and this is why i thought it wasnt working

wild oak
#

becuase i didnt put this thing

final iron
wild oak
#

in this

slate swan
final iron
slate swan
#

same as the other forks

wild oak
#

but

#

i put it in there

#

and it still dont work

#

do i put it here too

slate swan
#

ahh self has to be the first arg if your command is in a cog

wild oak
#

what

#

so like i can actually fix it

#

and dont have to give up

#

?

slate swan
#

yeah

wild oak
#

LETS GOOOOO

slate swan
#

put self aas the first arg

final iron
#

@wild oak Im guessing you didn't learn python basics before dpy?

wild oak
#

nope

#

kinda just skimmed it

final iron
#

These are the types of issues that leads to

wild oak
slate swan
#

fix the indent a bit

wild oak
#

bro

#

where

#

i tried 😩

#

welp

#

So the yogaball command works now

#

but same error for the help command

#

lmao

slate swan
#

thats because the cog returned a None

wild oak
#

how the dilly darn dang do i fix that

#

lmao

faint echo
#

Hello given that my bot has several modules(cogs) in it
I want to check if a command was executed from a specific cog, if this is True then # do something.

Is there an event that checks for commands in a specific cog?

I'm using Discord.py

wild oak
#

how do i fix that i thought i put the """ thing

slate swan
#
@client.event
async def on_message(message):

    if message.author == client:
        return

    if 'help' in message.content.lower():
        await message.channel.send('Hello, How can I help you?')
    await client.process_commands(message)

The bot reads. its own message and gets stuck in an infinite loop. How do i make the bot not read 'help' in its own message?

faint echo
#

I could be wrong here but try to use this code:

if not message.author.bot:
    #(everything goes in here)
    await self.process_commands(message)

#

@slate swan

slate swan
#

ok lemme try

wild oak
#

@slate swan I literally tried to fix it and i cant

faint echo
#

put your conditionals in there

wild oak
#

it keeps saying the same stupid thing

#

this is how my help commands set up this is the error and its becuase i added this new command

faint echo
wild oak
#

how can i see which one that doesnt have .get_commands()

#

i mean

faint echo
#

thanks

wild oak
#

Yes i can do you want a fuller ss?

faint echo
#

Well if you can just show u pto line 30

#

exactly

wild oak
#

whats wrong with it?

#

im quite slow so gimme a break 😂

wild oak
#

do you want to see the new cog?

faint echo
#

Yes

wild oak
faint echo
#

Well you seem to know the problem, one of your cogs is not being recognized

wild oak
#

Do you know why?

#

originally i thought this was the problem

#

becuase i didnt have this in the start

#

but it wasnt

faint echo
#

try doing something

wild oak
#

like what a diffrent command

faint echo
#

in line 30 of help.py
you have: i.lower()
take out the method

wild oak
#

ok

faint echo
#

just to see if this works

wild oak
#

ok brb

#

OHHH

#

Waait

faint echo
#

Works?

wild oak
faint echo
#

self.bot.get_cog(i) without the lower

wild oak
#

completely remove the line or just i.lower

#

OHHH ok

#

ohh

faint echo
#

no parenthesis

wild oak
faint echo
#

Ok

#

try now

wild oak
#

trying it

pliant gulch
#

What is the point of doing get_cog here?

wild oak
#

oh

faint echo
#

I'm guessing he wants to get the cog instance

pliant gulch
#

Bot.cogs is a dict which contains the cogs name as the key and the cog class itself...

wild oak
#

OH MY GO

pliant gulch
#

If you want all cogs you can just do for i in self.bot.cogs.values()

#

I don't really understand the point of get_cog

faint echo
wild oak
#

YOUR LITERALLY A GENIOUS DUDE

#

YES

faint echo
#

thats because cogs is case sensitive

#

you attempted to lower it

wild oak
#

OHHHHH

faint echo
#

so... problem

wild oak
#

OMG tysm

faint echo
#

take Andy's advice tho

#

his code will be better for you

wild oak
faint echo
#

no problem

wild oak
# faint echo no problem

No because you and maybe a few other people are experienced enough to see that because I'm honestly amazed

#

Im suprised you saw the issue

faint echo
#

I'm surprised too

wild oak
#

i was really gonna go without a help command 😂

faint echo
#

Lol.. help command is always helpful

#

no pun intended

slate swan
#
@client.event
async def on_message(message):
    if not message.author.bot:
        if ('help' in message.content.lower() or 'staff' in message.content.lower()):
            await message.channel.send('Hello, This is an automated message. If you are looking for the list of commands: Please do \"-com\".If you\'re looking for help beyond that: respond with yes. If you dont need help and this is a mistake: respond with no.')

            try:
                reply = await client.wait_for("reply", check = lambda m: m.author == message.author and m.channel == message.channel, timeout = 30.0)

            except asyncio.TimeoutError:
                await message.channel.send("This conversation will end because you failed to reply.")

            else:
                if reply.content.lower() == 'yes':
                    await message.channel.send('What specifically do you need help with?')

                elif reply.content.lower() == 'no':
                    await message.channel.send('Oh no! I\'m so sorry! Hope you are enjoying your time here at LOL.')

                else:
                    await message.channel.send('I cannot understand your reply. Sorry!')

    await client.process_commands(message)
#

anyone know why the bot dont respond even tho i said yes or no?

flint cosmos
#

Does anyone know what is going on here?

main.py:

@client.event
async def on_member_join(member):
    defaultRole = member.guild.get_role(defaultRoleID)
    await systemMessagesChannel.send(f"Welcome {member.mention} to the **Noobs Who Code** community, you noob!")
    await member.add_roles(member, defaultRole)

Exception:

2021-11-28T02:10:34.927060+00:00 app[worker.1]: Ignoring exception in on_member_join

2021-11-28T02:10:34.928638+00:00 app[worker.1]: Traceback (most recent call last):

2021-11-28T02:10:34.928659+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/nextcord/client.py", line 351, in _run_event

2021-11-28T02:10:34.928660+00:00 app[worker.1]:     await coro(*args, **kwargs)

2021-11-28T02:10:34.928667+00:00 app[worker.1]:   File "/app/main.py", line 29, in on_member_join

2021-11-28T02:10:34.928668+00:00 app[worker.1]:     await systemMessagesChannel.send(f"Welcome {member.mention} to the **Noobs Who Code** community, you noob!")

2021-11-28T02:10:34.928683+00:00 app[worker.1]: AttributeError: 'NoneType' object has no attribute 'send'
final iron
hexed moon
#

so how does this bot channel work

#

do i just ask my question and the bot will magically find an answer

flint cosmos
final iron
#

Is the ID correct?

flint cosmos
#

It wasn't doing this earlier, not sure what I changed... do you know if get_channel() requires a certain import ?

flint cosmos
#

It is working with my on_member_remove() so it can't be that

final iron
#

Can I see the code where its getting the channel?

carmine pilot
#

Can anyone create me a simple ping pong command with slash commands?

carmine pilot
carmine pilot
flint cosmos
flint cosmos
final iron
carmine pilot
flint cosmos
# carmine pilot .
from discord.ext import commands

client = commands.Bot(command_prefix="$") # you can define your prefix here lol

@client.command()
async def ping(ctx):
  await ctx.message.channel.send("pong")

client.run(put token here)
carmine pilot
#

(with slash commands?)

final iron
slate swan
#
@client.event
async def on_message(message):
    if not message.author.bot:
        if ('help' in message.content.lower() or 'staff' in message.content.lower()):
            await message.channel.send('Hello, This is an automated message. If you are looking for the list of commands: Please do \"-com\".If you\'re looking for help beyond that: respond with yes. If you dont need help and this is a mistake: respond with no.')

            try:
                reply = await client.wait_for("reply", check = lambda m: m.author == message.author and m.channel == message.channel, timeout = 30.0)

            except asyncio.TimeoutError:
                await message.channel.send("This conversation will end because you failed to reply.")

            else:
                if reply.content.lower() == 'yes':
                    await message.channel.send('What specifically do you need help with?')

                elif reply.content.lower() == 'no':
                    await message.channel.send('Oh no! I\'m so sorry! Hope you are enjoying your time here at LOL.')

                else:
                    await message.channel.send('I cannot understand your reply. Sorry!')

    await client.process_commands(message)

anyone know why this isnt working?

flint cosmos
final iron
#

!d discord.Client.latency then multiply it by 1000

unkempt canyonBOT
#

property latency: float```
Measures latency between a HEARTBEAT and a HEARTBEAT\_ACK in seconds.

This could be referred to as the Discord WebSocket protocol latency.
final iron
#

Creating a slash command will be different depending on which library you're using

final iron
slate swan
final iron
#

Also no need for the brackets in the if statement

slate swan
#

ok

final iron
#

I haven't worked with wait_for you could put print statements along your code to see where it stops though

slate swan
#

perfect, let me try

slate swan
final iron
#

Is reply a valid event?

slate swan
#

lemme try check = check

#

yes

#

1 sec

#

fixed it @final iron thanks

final iron
#

Nice

flint cosmos
#

Hey so I am trying to get a role object so I can add it to a user.
Code:

@client.event
async def on_member_join(member):
    defaultRole = member.client.get_role(defaultRoleID)
    systemMessagesChannel = client.get_channel(systemMessagesChannelID)
    
    await systemMessagesChannel.send(f"Welcome {member.mention} to the **Noobs Who Code** community, you noob!")
    await member.add_roles(defaultRole)

Exception:

2021-11-28T02:40:44.585128+00:00 app[worker.1]: Ignoring exception in on_member_join
2021-11-28T02:40:44.585562+00:00 app[worker.1]: Traceback (most recent call last):
2021-11-28T02:40:44.585583+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/nextcord/client.py", line 351, in _run_event
2021-11-28T02:40:44.585584+00:00 app[worker.1]:     await coro(*args, **kwargs)
2021-11-28T02:40:44.585586+00:00 app[worker.1]:   File "/app/main.py", line 23, in on_member_join
2021-11-28T02:40:44.585586+00:00 app[worker.1]:     defaultRole = member.client.get_role(defaultRoleID)
2021-11-28T02:40:44.585606+00:00 app[worker.1]: AttributeError: 'Member' object has no attribute 'client'

Im not sure how to get the role properly

slate swan
#
from nextcord.ext import commands


bot = commands.Bot(command_prefix= "??")

bot.command()
async def ping(ctx):
    await ctx.send("Pong!")

bot.run("*token*")```
Could someone tell me whats wrong with this code?
#

python.exe c:/Users/Windows/OneDrive/Desktop/Bot/main.py
Ignoring exception in command None:
nextcord.ext.commands.errors.CommandNotFound: Command "ping" is not found

it gives me this error

jade tartan
#

i really wanna get this code error sorted i need somones help

#
@client.event
async def on_raw_reaction_add(payload):
    if payload.member.bot:
        pass

    else:
        with open('reactrole.json') as react_file:
            data = json.load(react_file)
            for key, value in data:
                    if value['emoji'] == payload.emoji.name:
                        role = discord.utils.get(client.get_guild(
                        payload.guild_id).roles, id=['role_id'])

                    await payload.member.add_roles(role)
slate swan
#

I tried to add the bot to my server, not sure what happened but it did not seem to work?

jade tartan
#
Ignoring exception in on_raw_reaction_remove
Traceback (most recent call last):
  File "C:\Users\thoma\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\thoma\Desktop\discord.py\python\bot.py", line 38, in on_raw_reaction_remove
    for key, value in data:
ValueError: too many values to unpack (expected 2)
Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
  File "C:\Users\thoma\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\thoma\Desktop\discord.py\python\bot.py", line 76, in on_raw_reaction_add
    for key, value in data:
ValueError: too many values to unpack (expected 2)```
flint cosmos
slate swan
#

nopüe

#

nope still doesnt work

flint cosmos
#

Oh I know your problem

slate swan
#

fr? whats it

flint cosmos
#

You forgot the "@"

jade tartan
#

Anyone please?

slate swan
#

OHH

#

@flint cosmos i wish you and your family all the best

flint cosmos
jade tartan
#

Anyone plz?

slate swan
flint cosmos
slate swan
#

do you know how to make cogs? Ive tried it a few times now and ive failed

jade tartan
flint cosmos
flint cosmos
jade tartan
jade tartan
slate swan
flint cosmos
final iron
# jade tartan Meaning?

After a certain amount of boosts the server owner can change the invite link for the server

slate swan
bronze pilot
final iron
unkempt canyonBOT
#

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

bronze pilot
#

wtf looool

slate swan
bronze pilot
#

read smartass

flint cosmos
slate swan
#

or some like that

final iron
slate swan
flint cosmos
cerulean osprey
#

Id take the topic to DMs tbh

bronze pilot
#

I don't fully understand it yet but this is how it was implemented, and it works

final iron
#

Thats not ideal

slate swan
#

hm alright i think i understand it

final iron
#

You can loop through a directory where you store all your cogs and load them automatically instead of doing it manually

bronze pilot
#

wdym

slate swan
#

thats like the only thing i need rn

#

ion wanna do everything in the main file

bronze pilot
#

yeah I'm interested in how to do that now

final iron
#

This goes against my rule of spoon feeding but sure

bronze pilot
#

omg

final iron
#
for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        client.load_extension(f'cogs.{filename[:-3]}')
flint cosmos
#

I feel like some people just need to see how to stuff just saying

slate swan
#

ight thanks

final iron
#

edit client to what ever you defined your bot constructor as

cerulean osprey
#

Not sure

flint cosmos
final iron
#

With this bit os.listdir('./cogs') you would change 'cogs to what ever the folder name is that you stored your cogs in

slate swan
#

How can I find the code for these emojis: ✅ ❌

final iron
#

If the cogs folder is not in the same directory your main.py file is in you're going to have to provide a full path

cerulean osprey
sullen shoal
#

!d pkgutil.iter_modules

unkempt canyonBOT
#

pkgutil.iter_modules(path=None, prefix='')```
Yields [`ModuleInfo`](https://docs.python.org/3/library/pkgutil.html#pkgutil.ModuleInfo "pkgutil.ModuleInfo") for all submodules on *path*, or, if *path* is `None`, all top-level modules on `sys.path`.

*path* should be either `None` or a list of paths to look for modules in.

*prefix* is a string to output on the front of every module name on output.

Note

Only works for a [finder](https://docs.python.org/3/glossary.html#term-finder) which defines an `iter_modules()` method. This interface is non-standard, so the module also provides implementations for [`importlib.machinery.FileFinder`](https://docs.python.org/3/library/importlib.html#importlib.machinery.FileFinder "importlib.machinery.FileFinder") and [`zipimport.zipimporter`](https://docs.python.org/3/library/zipimport.html#zipimport.zipimporter "zipimport.zipimporter").

Changed in version 3.3: Updated to be based directly on [`importlib`](https://docs.python.org/3/library/importlib.html#module-importlib "importlib: The implementation of the import machinery.") rather than relying on the package internal [**PEP 302**](https://www.python.org/dev/peps/pep-0302) import emulation.
flint cosmos
# cerulean osprey I think its just `client.get_role()`
2021-11-28T02:57:11.670918+00:00 app[worker.1]: Ignoring exception in on_member_join
2021-11-28T02:57:11.671346+00:00 app[worker.1]: Traceback (most recent call last):
2021-11-28T02:57:11.671368+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/nextcord/client.py", line 351, in _run_event
2021-11-28T02:57:11.671368+00:00 app[worker.1]:     await coro(*args, **kwargs)
2021-11-28T02:57:11.671375+00:00 app[worker.1]:   File "/app/main.py", line 22, in on_member_join
2021-11-28T02:57:11.671375+00:00 app[worker.1]:     defaultRole = client.get_role(defaultRoleID)
2021-11-28T02:57:11.671391+00:00 app[worker.1]: AttributeError: 'Bot' object has no attribute 'get_role'

Welp worth a try

dusk pumice
slate swan
#

\✅

#

so.. this?

#

\❌

final iron
#

For beginners my method is just fine

dusk pumice
sullen shoal
slate swan
unkempt canyonBOT
#

bot.py lines 26 to 27

for cog in pkgutil.iter_modules(["cogs"]):
    bot.load_extension(f"cogs.{cog.name}")```
slate swan
cerulean osprey
dusk pumice
final iron
gaunt ice
sullen shoal
final iron
sullen shoal
#

yes

slate swan
final iron
#

Your method may be simple for you but for someone who has never heard of pkgutil its not

gaunt ice
slate swan
#

Traceback (most recent call last): File "c:\Users\Windows\OneDrive\Desktop\Bot\main.py", line 12, in <module> bot.load_extension(f'cogs.{filename[:-3]}') File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\bot.py", line 733, in load_extension self._load_from_module_spec(spec, name) File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\bot.py", line 678, in _load_from_module_spec raise errors.ExtensionFailed(key, e) from e nextcord.ext.commands.errors.ExtensionFailed: Extension 'cogs.mainhelp' raised an error: CommandRegistrationError: The command help is already an existing command or alias. PS C:\Users\Windows\OneDrive\Desktop\Bot>
Anyone got an idea of what this means?

sullen shoal
#

pkgutil is a useful built-in module, they should know about it, there's no fix time for beginners to know them

slate swan
gaunt ice
#

so basically discord.py made this update abt the help cmd every bot has

flint cosmos
slate swan
gaunt ice
flint cosmos
slate swan
#

yeah aight

#

forgot nextcord is just forked

final iron
flint cosmos
final iron
#

Anyway its only a 1 line difference

#

It doesn't matter.

sullen shoal
flint cosmos
#

Can someone explain to me how to use the get_role() because all the docs tells me is that I need to put an ID in as an argument but I dont know if I should be doing member.get_role() or whatever lol

slate swan
#

``PS C:\Users\Windows\OneDrive\Desktop\Bot> & C:/Users/Windows/AppData/Local/Programs/Python/Python39/python.exe c:/Users/Windows/OneDrive/Desktop/Bot/main.py
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\core.py", line 720, in _parse_arguments
next(iterator)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\client.py", line 351, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\bot.py", line 1035, in on_message
await self.process_commands(message)
File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\bot.py", line 1032, in process_commands
await self.invoke(ctx)
File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\bot.py", line 995, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\core.py", line 887, in invoke
await self.prepare(ctx)
File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\core.py", line 821, in prepare
await self._parse_arguments(ctx)
File "C:\Users\Windows\AppData\Local\Programs\Python\Python39\lib\site-packages\nextcord\ext\commands\core.py", line 722, in _parse_arguments
raise nextcord.ClientException(f'Callback for {self.name} command is missing "ctx" parameter.')
nextcord.errors.ClientException: Callback for helpme command is missing "ctx" parameter.``
Bro what?

#

it doesnt make sense

#

where am i missing the ctx

visual island
#

the first argument should be "self" and ctx second

slate swan
#

fixxed it. Yeah i figured thanks. Could you explain to me what self does?

sullen shoal
#

that is the instance of the class

#

every method's first parameter is the instance of the class

#

staticmethod dont need it tho but lets not talk about them

#

it can be named anything, but you should name it self

gaunt ice
#

but u can get a role from the guild

sullen shoal
#

!e

class Foo():
    def __init__(self):
        self.name = "myxi"
    def method(self, name):
        print(self.name)
        self.name = name
        print(self.name)

foo = Foo() #this is our instance, doing this will call __init__ method. there are a few other methods that get called too but this is the one which is mostly useful
foo.method("prime")
slate swan
#

that was a pain

unkempt canyonBOT
#

@sullen shoal :white_check_mark: Your eval job has completed with return code 0.

001 | myxi
002 | prime
flint cosmos
gaunt ice
unkempt canyonBOT
sullen shoal
#

utils method is slow, you shouldn't stick with that

flint cosmos
sullen shoal
#

get_role is a method of discord.Guild

#

you need an instance of discord.Guild

flint cosmos
sullen shoal
#

commands.Context returns the guild with one of it's attributes, discord.Message returns it with one of its attributes as well

#

you may check their docs

flint cosmos
#

But do I put like.. client.get_role() ?

sullen shoal
#

member ie discord.Member

#

i just explained you how to use it

flint cosmos
sullen shoal
#

what is your confusion

flint cosmos
#

Ok so I have a on_member_join().
I need to give a member a role inside of that function.
In order to do this I believe I need a role object so I can use add_roles().
I need to know what to put before the get_role(roleID) in this case.
I tried client.get_role(roleID) but that did not seem to work.
I don't know what exactly to put in this case.

unkempt canyonBOT
visual island
#

member.guild is a discord.Guild instance

sullen shoal
#

this event's first parameter (except the class instance) is discord.Member instance

maiden fable
hollow agate
#
@client.command()
async def testing(ctx):
    embed1 = discord.Embed(
        title="",
        description=
        f"Embed1",
    color=discord.Color.purple())
    embed2 = discord.Embed(
        title="",
        description=
        f"Embed2",
    color=discord.Color.purple())
    await ctx.send(embed=embed1, embed=embed2)``` How would I send both the embeds?
maiden fable
#

embeds=[]

#

Also just skip the title kwarg if u don't wanna set one

hollow agate
#
    await ctx.send(embeds=embed1, embed2)``` Doesn't seem to work, but I probably misunderstood you
maiden fable
#

send(embeds=[embed1, embed2])

hollow agate
#

Ahh, thank you!

slate swan
#
@client.event
async def on_message(message):
    if not message.author.bot:
        if 'help' in message.content.lower() or 'staff' in message.content.lower():
            embed = discord.Embed(description = '**__Hello, This is an automated message.__** \n- If you are looking for the list of commands: Please do \"-com\". \n- If you\'re looking for help beyond that: respond with \"yes\". \n- If you dont need help and this is a mistake: respond with \"no\".')
            await message.channel.send(embed = embed)
#

How do i make the bot respond in a different channel?

sullen shoal
#

!d discord.TextChannel.send

unkempt canyonBOT
#

await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Sends a message to the destination with the content given.

The content must be a type that can convert to a string through `str(content)`. If the content is set to `None` (the default), then the `embed` parameter must be provided.

To upload a single file, the `file` parameter should be used with a single [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") object. To upload multiple files, the `files` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") objects. **Specifying both parameters will lead to an exception**.

To upload a single embed, the `embed` parameter should be used with a single [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") object. To upload multiple embeds, the `embeds` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") objects. **Specifying both parameters will lead to an exception**.
slate swan
#

[perfect thanks

sullen shoal
#

you need an instance of TextChannel, not the class itself.
discord.Message.channel returns it
thats why you did message.channel.send because
message which is discord.Message has an attribute channel which returns it

#

!d discord.ext.commands.Bot.get_channel

unkempt canyonBOT
sullen shoal
#

!d discord.Guild.get_channel

unkempt canyonBOT
#

get_channel(channel_id, /)```
Returns a channel with the given ID.

Note

This does *not* search for threads.
gaunt ice
maiden fable
gaunt ice
#

it doesnt

slate swan
#

okay so ive added a button to my bot, and i wanted to know if its possible to show this message "Coming!" as an Embed and not just a normal message (nextcord)

maiden fable
# gaunt ice it doesnt

Breg in small operations it doesn't, but when your bot gets bigger and stuff, it will start taking

gaunt ice
#

k

slate swan
maiden fable
#

send_message()

gaunt ice
slate swan
maiden fable
#

No, inside it 🤦

slate swan
#

oh yeah saw it but whenever i do embed = discord.Embed(title..etc)

#

it says discord is not defined

maiden fable
#

Then do nextcord.Embed

slate swan
#

alr thanks

slate swan
# maiden fable Then do nextcord.Embed

PS C:\Users\Windows\OneDrive\Desktop\Bot> & C:/Users/Windows/AppData/Local/Programs/Python/Python39/python.exe c:/Users/Windows/OneDrive/Desktop/Bot/cogs/mainhelp.py
File "c:\Users\Windows\OneDrive\Desktop\Bot\cogs\mainhelp.py", line 12
await interaction.response.send_message(embedR = nextcord.Embed(title="title", description="smh")), ephemeral=True)
^
SyntaxError: cannot assign to await expression
PS C:\Users\Windows\OneDrive\Desktop\Bot>

#

now how would i fix this

#

question how can you make the !e command from the python bot?

sullen shoal
slate swan
sullen shoal
#

!src e

unkempt canyonBOT
#
Command: eval

Run Python code and get the results.

Source Code
slate swan
slate swan
#

fixed it

#

it works thanks a lot @maiden fable

#

next question, is there a way i could add buttons to a message sent from the bot because the user clicked on a button?

wintry panther
#

does someone have a script that makes bots leave all the server its in

#

i only found out how to do it when someone messages something

sullen shoal
#

!d discord.Client.guilds

unkempt canyonBOT
#

property guilds: List[discord.guild.Guild]```
The guilds that the connected client is a member of.
sullen shoal
#

!d discord.Guild.leave

unkempt canyonBOT
#

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

Leaves the guild.

Note

You cannot leave the guild that you own, you must delete it instead via [`delete()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.delete "discord.Guild.delete").
slate swan
#

how to resolve this?

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Windows\Desktop\MyBot.py", line 41, in on_message
    if client.is_voice_connected(message.server):
AttributeError: 'Client' object has no attribute 'is_voice_connected'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Windows\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Windows\Desktop\MyBot.py", line 85, in on_message
    await client.send_message(message.channel, "Error: [{error}]".format(error=e))
AttributeError: 'Client' object has no attribute 'send_message'```
brittle ingot
#

You’re using a tutorial video in YouTube?

slate swan
#

no

#

anybody know the reason of this error?

disnake.ext.commands.errors.UnexpectedQuoteError: Unexpected quote mark, '"', in non-quoted string
brittle ingot
#

It’s severely outdated code.

tiny ibex
#

Can someone tell me how did the time thing in the footer update automatically

#

And how is it synced to my timezone when it looks different to other people

brittle ingot
sullen shoal
#

!d discord.ext.commands.errors.UnexpectedQuoteError

unkempt canyonBOT
#

exception discord.ext.commands.UnexpectedQuoteError(quote)```
An exception raised when the parser encounters a quote mark inside a non-quoted string.

This inherits from [`ArgumentParsingError`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.ArgumentParsingError "discord.ext.commands.ArgumentParsingError").
sullen shoal
#

looks like the command arguments has a "

tiny ibex
slate swan
#

Hey yall how can i make my bot send a perfect embed from a message that comes from a button? I cant see finding out how

brittle ingot
#

Define the embed first then send it with the interaction response…

tiny ibex
slate swan
slate swan
slate swan
# tiny ibex Bruh

its just for training i aint that good at python so i gotta work on something

sullen shoal
slate swan
#
AttributeError: 'Client' object has no attribute 'is_voice_connected'
AttributeError: 'Client' object has no attribute 'send_message'```
#

client object?

#

what

tiny ibex
sullen shoal
#

thats not keyword only argument

slate swan
#

yeah ik

sullen shoal
#

ctx, *, arg

brittle ingot
slate swan
#

im going to try it

tiny ibex
sullen shoal
#
command(ctx, arg, arg2): pass

if you do the command smth like this,

.command "hello world oof i" hello

first arg will contain the content inside the quotes and the second one hello

slate swan
#

how can i fix an error if it says ctx is not defined?

slate swan
tiny ibex
slate swan
tiny ibex
#

And won't be synced to other member's timezones

slate swan
#

I guess there was some change in the api recently requiring you to pass .... maybe utc aware object iirc

#

what datetime object did you pass?

slate swan
#

how did the bot send this type of text

#

the black background and white text

slate swan
tiny ibex
slate swan
sullen shoal
tiny ibex
slate swan
#

Do you mean to bold it too? Try **`text_here`**

#

yes that works

#

Does anyone know what i should replace author with in the m.channel == ?

#

its usually the channel that the message is going to be read, i want to set to to author.dms

maiden fable
#

m.channel == user?

#

Ig?

slate swan
#

lemme try

#
dm = await message.author.create_dm()
m.channel == dm
#

whats bots you guys making

slate swan
maiden fable
slate swan
#

ok this is pretty weird lmao

#

@maiden fable

#

so, here's my code:

slate swan
slate swan
slate swan
#

Instead do m.channel == user.dm_channel

#

Why do you need to comsume a request ...?

#

is that bad in any way?

#

Umm sorry it's fine.. It first checks if dm_channel exists

#

So you're good with it

#

Umhmm

#

1 thing, if you're free

#

@slate swan

#

Sure

#

so this is my code:

#
@client.event
async def on_message(message):
    if not message.author.bot:
        if 'help' in message.content.lower() or 'staff' in message.content.lower():
            dm = await message.author.create_dm()
            embed = discord.Embed(description = f'**__Hello {message.author.mention}, This is an automated message.__** \n- If you are looking for the list of commands: Please do \"-com\". \n- If you\'re looking for help beyond that: respond with \"yes\". \n- If you dont need help and this is a mistake: respond with \"no\".')
            await dm.send(embed = embed)

            try:
                reply = await client.wait_for('message', check = lambda m: m.author == message.author and m.channel == dm, timeout = 30.0)

            except asyncio.TimeoutError:
                reply_embed = discord.Embed(description = 'This conversation will end because you failed to reply.')
                await message.author.send(embed = reply_embed)

            else:
                if reply.content.lower() == 'yes':
                    embed = discord.Embed(description = 'What specifically do you need help with?')
                    await message.author.send(embed=embed)

                elif reply.content.lower() == 'no':
                    embed = discord.Embed(description = 'Oh no! I\'m so sorry! Hope you are enjoying your time here at DSRP.')
                    await message.author.send(embed=embed)

                elif reply.content.lower() == '-com':
                    embed = discord.Embed(description = 'There\'s your list of commands')
                    await message.author.send(embed=embed)

                else:
                    embed = discord.Embed(description = 'I cannot understand your reply. Sorry!')
                    await message.author.send(embed = embed)

    await client.process_commands(message)

when a user inputs -com, it responds with a custom client.group and the bot basically outputs the group + "here's your list"

#

How can i fix this error? "ctx" is not defined.

upbeat otter
slate swan
#

You mean you need to list the commands of that group?

#

no

glad scarab
slate swan
#

the bot is somehow printing that list the commands command in dms and hhanding me a huge error

#

Umm also, what is client.group?

#

its working but its giving me a huge error

#

Error?

slate swan
#

lemme send error

#

oh okay

upbeat otter
#

Either make your bot check the added bot's permissions and ping a staff whose online

slate swan
slate swan
#
Ignoring exception in command com:
Traceback (most recent call last):
  File "/home/lol/miniconda3/lib/python3.9/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/lol/bot.py", line 27, in com
    await ctx.message.delete()
  File "/home/lol/miniconda3/lib/python3.9/site-packages/discord/message.py", line 1023, in delete
    await self._state.http.delete_message(self.channel.id, self.id)
  File "/home/lol/miniconda3/lib/python3.9/site-packages/discord/http.py", line 248, in request
    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50003): Cannot execute action on a DM channel

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

Traceback (most recent call last):
  File "/home/lol/miniconda3/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/home/lol/miniconda3/lib/python3.9/site-packages/discord/ext/commands/core.py", line 1353, in invoke
    await super().invoke(ctx)
  File "/home/lol/miniconda3/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/lol/miniconda3/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50003): Cannot execute action on a DM channel
#

its working but its handing me this error, should i be worried?

upbeat otter
slate swan
#

thanks a lot

upbeat otter
slate swan
#
def stickbug_vid(url, link):
    endpoint=neko_base+"stickbug&url="+str(url)
    link[0]=(requests.get(endpoint).json()["message"])

@Blank.command(aliases=["sb", "stb"])
async def stickbug(ctx, user: discord.Member=None):
    await ctx.message.delete()
    await ctx.channel.send("It will take a little bit of time", delete_after=2.0)
    if user is None:
        user=ctx.message.author
    url=[None]
    t1=Thread(target=stickbug_vid, args=((user.avatar_url_as(format="png"), url))).start()
    t1.join()
    try:
        file=io.BytesIO(requests.get(url[0]).content)
        await ctx.channel.send(file=discord.File(file, 'stickbug.mp4'))
    except Exception:
        await ctx.channel.send(url)```

Error: Nonetype object has no attribute join
slate swan
#

You can't, as the error says

#

ahh okay understood

#

i'll just ignore it lol

slate swan
#

Just remove the .delete() call, or suppress the error so that it don't affect anything else

maiden fable
slate swan
slate swan
upbeat otter
maiden fable
slate swan
upbeat otter
slate swan
#

!d contextlib.suppress

unkempt canyonBOT
#

contextlib.suppress(*exceptions)```
Return a context manager that suppresses any of the specified exceptions if they occur in the body of a `with` statement and then resumes execution with the first statement following the end of the `with` statement.

As with any other mechanism that completely suppresses exceptions, this context manager should be used only to cover very specific errors where silently continuing with program execution is known to be the right thing to do.

For example...
slate swan
#

ill try if it works without ephemeral on

slate swan
upbeat otter
#

@maiden fable yes nqn uses buttons on them too

maiden fable
slate swan
#
with contextlib.suppress(Exception):
    # do whatever can error and you need to suppress it
upbeat otter
maiden fable
slate swan
#

so what could the error in my code be?

upbeat otter
maiden fable
slate swan
#

...

slate swan
slate swan
slate swan
slate swan
#

It can only purge it's own messages

#

but not the users'

#

sounds good

slate swan
#

!args-kwargs

unkempt canyonBOT
#

*args and **kwargs

These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names args and kwargs are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (*). If both are used in a function signature, *args must appear before **kwargs.

Single asterisk
*args will ingest an arbitrary amount of positional arguments, and store it in a tuple. If there are parameters after *args in the parameter list with no default value, they will become required keyword arguments by default.

Double asterisk
**kwargs will ingest an arbitrary amount of keyword arguments, and store it in a dictionary. There can be no additional parameters after **kwargs in the parameter list.

Use cases
Decorators (see !tags decorators)
Inheritance (overriding methods)
Future proofing (in the case of the first two bullet points, if the parameters change, your code won't break)
Flexibility (writing functions that behave like dict() or print())

See !tags positional-keyword for information about positional and keyword arguments

slate swan
#

Lol

pale turtle
#

I would suggest you'd learn vasic Python brfore approaching the discord.py library, as it is a complicated that involved a lot of advanced Python library

slate swan
#

i am learning both, its just that sometimes i forget some easy things

slate swan
#

I understood I mixed .start() with the thread

bitter perch
#

you're mutating a list instead of returning

slate swan
#

huh?

bitter perch
#
def stickbug_vid(url, link):
    endpoint=neko_base+"stickbug&url="+str(url)
    link[0]=(requests.get(endpoint).json()["message"])
#

just, return?

slate swan
#

IDK if return would work

#

on threading

bitter perch
#

better yet use aiohttp

#

and not use threading

slate swan
#

how can I, i never used aiohttp for this function

bitter perch
#

read the aiohttp quickstart docs

#

they will tell you all you need to know about using it

slate swan
#

!e```py
from threading import Thread

def function(arg, s):
s[0]=arg
t=[None]
a=Thread(target=function, args=(3, t))
a.start()
a.join()
print(t[0])```

#

\🤔

bitter perch
#

this seems like a "why use threading" moment of overcomplication

slate swan
#

🤷‍♂️

#

!e```py
from threading import Thread

def function(arg, s):
s[0]=arg
t=[None]
a=Thread(target=function, args=(3, t))
a.start()
a.join()
print(t[0])```

bitter perch
#

use aiohttp

slate swan
#

hmmm...

pliant gulch
#

Why are you using threading with an asynchronous environment

bitter perch
#

threading is the answer to all problems of course

#

until you discover gil

lament mesa
#

multiprocessing lemon_fingerguns_shades