#discord-bots
1 messages ยท Page 731 of 1
And make sure it doesn't fail to do so
Pretty sure all fetch_ methods raise an exception when what they're supposed to be fetching doesn't exist
do i need to use try except or is there a method which return none ?
if there is none
!d discord.TextChannel.fetch_message
await fetch_message(id, /)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Retrieves a single [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") from the destination.
And it's a coroutine
!d inspect.getfullargspec
inspect.getfullargspec(func)```
Get the names and default values of a Python functionโs parameters. A [named tuple](https://docs.python.org/3/glossary.html#term-named-tuple) is returned:
`FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)`
I saved channel_id and message_id in an database and I wanted to use add reaction to start a task. I want to be able to still use it after I close and run the script. I know I can use on_raw_reaction_add and check the message id but is there a alternative way to do this without on_raw_reaction_add ?
let me guess
you have some sort of "role adding" message, and based on the reaction, it adds the role to that user?
similar but no I am making a music bot
I want to press on any reaction and it will do what I want it to do. But if i use something like menus ? if I close the script it will broke right ? I want it to check if someone have added a reaction but without raw_reaction_add
how long do you want these "buttons" to work?
forever
It's the only way
I dont want to take risk of server going down and broke this in every server
What
is that the only message in that channel? because else, I'd be hard to find once people type under it
Oh you mean the one hosting your bot
this will be the only message that the bot will send in that channel
any other message auto delete
why don't you just make the bot the only one to be able to type in that channel (send_messages) permission?
i query the music by using msg.content then delete it after done query
so anyone can be a dj in that channel?
yes
they can only "request" music in that channel?
the first one who request/admins perm will be the dj
they will be the one able to use the reaction
but any other can request song
why would this break, you think?
the bot will just have to refresh that message in the db... since it's not playing anything anymore ofc
you just need a startup task which loads everything back in (the asked music etc)
unless you just say "fuck it, whenever the bot restarts, the music gets deleted"
the buttons will still work fine if you use an event AND store the messageID's in your db...
is there any alternative that i can use instead of on_raw_reaction_add ?
why would you want that?
there is, but what you mentioned is the most efficient way...
just store everything in a musicCog, so you can organize it...
Hmm so I should use on_raw_reaction_add only right as it is the most efficient way
yea but if i restart my bot will that button still work ?
no
just update the view with new buttons lol
wdym by update the view ?
class disnake.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.
Or use the interaction event.
ok ok I think I got a rough idea I should get working. thx all
!d disnake.on_interaction
disnake.on_interaction(interaction)```
Called when an interaction happened.
This currently happens due to application command invocations or components being used.
Warning
This is a low level function that is not generally meant to be used.
New in version 2.0.
If you're using disnake, which is recommended.
And it's an event, just like on_raw_reaction_add
await interaction.edit_original_message(view=self)
something like this
ok ok thx
default_value = inspect.getfullargspec(error.param)```
raises ```py
await Missing_Args(ctx, error)
File "c:\Users\tenuk\Desktop\Coding\bot_2\Error_Embeds.py", line 11, in Missing_Args
default_value = inspect.getfullargspec(error.param)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\inspect.py", line 1171, in getfullargspec
raise TypeError('unsupported callable') from ex
TypeError: unsupported callable```
How to colour the text
```diff
- Green
- Red
```
.bm
diff?
It's for file difference
And how many of these colours exist??
Therefore the name
plus is green and red is negative right
It's based on programming languages and other things, you can't choose the language you want.
Are there just 2 of them?
not sure lol
There are very limited colors since they are code blocks.
ahhh ic
Possible on embeds?
Are there more colours?
No
is it a programming language?
Tysm bro
Uhm ty
Man are there any kind of docs?
AHHH
And for blue it's not diff, but ini
ic
Some Yellow?
Which language?
ml
Hella cool
That's pretty much all I know, maybe you can find more on internet
I'll try to
Goodbye
F#?
DAMN tyyy
But haven't seen any other colors
thanks
@spring flax u fixed the error?
disnake/client.py", line 515, in _run_event
await coro(*args, **kwargs)
TypeError: on_member_join() takes 1 positional argument but 2 were given
``` huh?
mind bumping it once?
code
Ah cool
@commands.Cog.listener("on_member_join")
async def on_member_join(member : disnake.Member):
it's a cog
self, member
if payload.emoji in ["โฏ","โญ","โน","๐","๐","๐","๐","๐"]:```
why doesnt this get executed when i use one of the emoji in the array ?
You need to convert the emoji to a string, so str(payload.emoji)
how i change discord.py ```py
@tasks.loop(seconds=120)
async def service(self):
aparently wasnt easy as just do from disnake.ext import task, commands
aparently no task
disnake.ext.tasks.loop(*, seconds=..., minutes=..., hours=..., time=..., count=None, reconnect=True, loop=...)```
A decorator that schedules a task in the background for you with optional reconnect logic. The decorator returns a [`Loop`](https://docs.disnake.dev/en/latest/ext/tasks/index.html#disnake.ext.tasks.Loop "disnake.ext.tasks.Loop").
Wtf is disnake
!pypi disnake
So it's literally the same as discord.py or?
A discord.py fork and replacement, since discord.py has stopped development.
disnake is getting updates, unlike discord.py.
There is a list of change logs.
no its a fork
But since it's a discord.py fork there is almost nothing to change.
disnake will be the best fork trust me
Ok cool
That's what I meant lol
!d discord on_kick
To work with the library and the Discord API in general, we must first create a Discord Bot account.
Creating a Bot account is a pretty straightforward process.
#bot-commands for random commands please :p
how do i check if a member in the on_member_remove was kicked?
Use the audit logs.
!d discord.Guild.audit_logs
async for ... in audit_logs(*, limit=100, before=None, after=None, oldest_first=None, user=None, action=None)```
Returns an [`AsyncIterator`](https://discordpy.readthedocs.io/en/master/api.html#discord.AsyncIterator "discord.AsyncIterator") that enables receiving the guildโs audit logs.
You must have the [`view_audit_log`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.view_audit_log "discord.Permissions.view_audit_log") permission to use this.
Examples
Getting the first 100 entries:
```py
async for entry in guild.audit_logs(limit=100):
print(f'{entry.user} did {entry.action} to {entry.target}')
```...
thank you!
Hello to all. Tell me please. I wrote a music bot and everything works fine, but the sound quality is lame, is there any way to fix it?
hi
member timeout ?
We sadly won't help you for music bots.
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
!ytdl
Per Python Discord's Rule 5, we are unable to assist with questions related to youtube-dl, pytube, or other YouTube video downloaders, as their usage violates YouTube's Terms of Service.
For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2021-03-17:
The following restrictions apply to your use of the Service. You are not allowed to:
1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service; (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;
3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTubeโs robots.txt file; (b) with YouTubeโs prior written permission; or (c) as permitted by applicable law;
9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
nope with mute bro it means that ya timeout
Therefore rule 5 is more accurate since it applies to music bots in general.
i ment the coro
And not just music bots using youtube_dl and similar
ยฏ_(ใ)_/ยฏ
!d disnake.Member.timeout
await timeout(*, duration=..., until=..., reason=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Times out the member from the guild; until then, the member will not be able to interact with the guild.
Exactly one of `duration` or `until` must be provided. To remove a timeout, set one of the parameters to `None`.
You must have the [`Permissions.moderate_members`](https://docs.disnake.dev/en/latest/api.html#disnake.Permissions.moderate_members "disnake.Permissions.moderate_members") permission to do this.
New in version 2.3.
Sorry...
your command?
like
its a coro not a function
i mean yeah it is a function
not the point
async def timeout(????)
like in the place of ???? what should I write
ctx, <your args>
also, the decorator is @client.command()
that's optional
you can just do ctx
!timeout will run that command if ! was your prefix
@bot.command()
async def ban(ctx, member: disnake.Member=None,time: int=None, *, reason=None) -> None:
if not member:
return await ctx.send("specify the member")
await member.timeout(duration=time, reason=reason)
the spoonfeed smh
my prefix is %
%ban
the return type isn't 100% correct and unnecessary
that would be none
ya
not needed, no-one checks command return types
you're returning a message object in the if statement
i just go by what pylance says lol
thats if it gets triggered
and why can i not follow pep 484 lol
ya lemme see
it can be none OR the message object, but ok
my bot is online
then it can be any
doesnt any get set as None?
it would be typing.Optional[discord.Message]
ig not i think it gets set as Any
how
if it can return nothing as well?
that's None... that's what the Optional is for...
i just set as none if it can return anything lol
that would be incorrect then xd
let me check docs
but yeah, that doesn't throw errors... it's just to help devs...
I only use the typehinting for args and help functions, not commands, since I'll never use whatever they return
None isn't the same as Any
Using None
When used in a type hint, the expression None is considered equivalent to type(None).
smh how did i not see that
any cool suggestions for a discord bot?
do you want to make it useful? implement other API's
hmm i wanna make like an arcade bot ig
yk like tictactoe, snake, hangman, all in one
@bot.command()
async def balance(ctx):
await open_account(ctx.author)
user = ctx.author
users = await get_bank_data()
wallet_amt = users[str(user.id)]["Wallet"]
bank_amt = users[str(user.id)]["Bank"]
em = discord.Embed(title=f"{ctx.author.name}'s balance.", color=discord.Color.teal())
em.add_field(name="Wallet Balance", value=wallet_amt)
em.add_field(name="Bank Balance", value=bank_amt)
await ctx.send(embed=em)```
I copied this code and i dont have errors, i just dont know what to type in doscord, anyone knows?
in the users await get_bank_data()
that's terrible, copying code without knowing what it does
put a : after the data
he copied it?
huh?
dayum
.
@potent spear how can i learn more about typing and optional return types?
the typing library is full of examples
you know what Union is?
a bit
not much
Union can be one of 2 datatypes
Union[int, str]
if it were to be like this
Union[None,int]
then that basically is this
Optional[int]
the typing lib is full of examples etc
ah i see so as it says it can be optional and its expecting a int?
anyone has python tic tac toe bot code?
Union[None, int] == Optional[int]
it's basically better written if you use Optional
theirs examples in disnake
ok i see thank you
just do it without the bot first, then implement it, simple array stuff
in google
!pypi disnake
Hi, is there a method to restart a loop like we start or stop it with myLoop.start()
Something like... myLoop.restart()
!d discord.ext.tasks.Loop.restart
restart(*args, **kwargs)```
A convenience method to restart the internal task.
Note
Due to the way this function works, the task is not returned like [`start()`](https://discordpy.readthedocs.io/en/master/ext/tasks/index.html#discord.ext.tasks.Loop.start "discord.ext.tasks.Loop.start").
YES
better option is to make a command out of it
.bm
Would be too much of flood to always send the message
true
could u include yaml yaml green text
, ```ini
[ini cool blue text]
See other pinned messages ^^
ah ini is already there
Added green, thanks ^^
I'd prefer you to put this line
This one is special, all words need to start with an upper case.
Under Yellow instead of above Dark Grey
it's confusing
whats the code to check if a user dmed you a certain message
True, changed; thanks :)
use on_message event and use isinstance(message.channel , DMChannel)
@tiny ibex ^
ok thanks
https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51 in case someone needs a complete markdown guild , covers most of the things
forgot this color?```
nvm, it's not consistent
.bm
@client.command()
async def on_message(msg):
if discord.ChannelType.private:
if msg.content.startswith(';suggest '):
Like this?
no
why my slash commands nvr shows up after made a newserver or cant have slash commands now cus bot owner of server?
no? shit me
@client.event
async def on_message(msg):
if discord.ChannelType.private:
if msg.content.startswith(';suggest '):
Have you searched what msg even contains?
BTW why not make it just like this
@client.command()
@commands.dm_only()โ
async def suggest(ctx):
#do something ```
Yeah making commands with startswith is pretty much not it
This will always be true really unneeded if...
idk im still tryna learn how to do anything
Huh?
What did you even put in the if?
To check if the channeltype is private ig?
You just referenced an Enum item.
They can just use the decorator....
!d discord.ext.commands.dm_only
@discord.ext.commands.dm_only()```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that indicates this command must only be used in a DM context. Only private messages are allowed when using the command.
This check raises a special exception, [`PrivateMessageOnly`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.PrivateMessageOnly "discord.ext.commands.PrivateMessageOnly") that is inherited from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").
New in version 1.1.
!d discord.ext.commands.PrivateMessageOnly raises this
exception discord.ext.commands.PrivateMessageOnly(message=None)```
Exception raised when an operation does not work outside of private message contexts.
This inherits from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure")
Hi, I've been having this issue when starting the bot. I'm hosting on cubes.host
!intents
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.
guys, ;-; how do I check if anyone is mentioned in a message?
if message.mentions:
# code
the same time I search stack
tysm, lovely
imagine doing that-
most importantly which IDE are you using, it depends quite a lot
have you done this?
then do it
that's the reason
bro did you jump straight to discord.py
How can I immediately start a task when the bot comes online?
The task is stored in another cog
do you....understand python basics?
start your loop in on_ready 
cool, now pip install it
i HaVe No ExPeRiEnCe In PyThOn, In FaCt I dOn'T wAnT tO lEaRn PyThOn, I jUsT wAnT tO cReAtE a DiScOrD bOt To ImPreSs My FrEiNdS
I know how to do that, but I am unable import the task.loop in the main file
My task is a loop, so... yeah
Start your loop in the cog init lol
don't do that
from discord.ext import tasks
from your_file import ...
# idk
@bot.event
async def on_ready():
your_task.start()
why 
don't do that
why 
don't do shit in on_ready, it can get called multiple times,it's good for a print, that's all
true 
So should I just run the loop in the cog init?
make sure that if you do API calls in that loop, you have a before loop which waits until the bot is ready
there's actually gone be just a lil delay, hardly matters even if you dont start it in on_ready
can anyone help me ?#help-chili
I've made sure of that
I've been calling task.loop for a loop called checkTime
Sorry if that caused any confusion
It's something like this...
@tasks.loop(seconds=1)
async def checkTime(self):
#Does some stuff...```
discord.ext.tasks.loop(*, seconds=..., minutes=..., hours=..., time=..., count=None, reconnect=True, loop=...)```
A decorator that schedules a task in the background for you with optional reconnect logic. The decorator returns a [`Loop`](https://discordpy.readthedocs.io/en/master/ext/tasks/index.html#discord.ext.tasks.Loop "discord.ext.tasks.Loop").
*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
people do it not to import everything for faster speeds
or less storage iirc
from lib import something
your only importing something from the lib
in what
i dont think thats how it works
what lib?
so dpy?
dpy doesnt have timeout lol
what library should i use to create timeouts commands
any fork lol
disnake is good
^
hmm
how do I get the channel id on message event?
bot.get_channel(id)
this?
i don't think the way you're supposed to install it on windows works in Repl.it
because i'm using repl.it
on message event tho
well im not sure i dont use replit
aww
thats how you get a channel obj?
how do you download a lib in replit?
pip install or are they there by default
I ask how to get the channel id and u send me a code with the id already defined
id is an example lmfao you actually have to add the id
it automatically installs libraries by putting import something in the code
but it doesn't seem to work for forks
oof
look at my question wtf?
lemme try pip install with disnake rq
your trying to get a channel obj right?
I don't need the channel object I need the channel id when someone sends a message
no read the question wtf
smh.. ๐คทโโ๏ธ
thanks man, someone who actually read the question
yup
oi, still here
thats a command you can clearly see context
but if its on the event on_message(message)
then its message.channel.id, message.guild.id
yes
commands are messages, whether they are slash or normal
and r u ok? cuz I asked u how to get the channel id by message and u sent me the event lol
commands take context ๐
@steady thicketyou dont import it
do you know basic oop?
or docs?
the point is you didn't read my question lol
yes but I saw this
then how was it so hard to add message.
@steady thicket```py
intents = discord.Intents.all()
intents.guilds = True
intents.members = True
intents.presences = True
intents.typing = True
bot = commands.Bot(.., intents=intents)
i see.ext
you do like that
bot = commands.Bot(.., intents = discord.Intents.all())
looks better
but it's not it, its channel.id and not channel_id
@slate swanmaybe he dont want all ๐
stop being annoying, read messages too
just set defualt
yup
then actually be smart smh
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents ,case_insensitive=True, strip_after_prefix=True)``` or like this, and you turn intents on on the bot's dev page
so like this, right?
@stray thistleexactly
on message doesnt take context smh
smart? lol, you don't even know me. I was confused since I saw channel_id. that's all
^
@steady thicketbut u have 2 diffrent intents ๐
no actually add it to your bot constructor
and two diffrent bot
yeah
now I'm confused
or just copy this
shouldnt tbh

so I'll replace this (image) with mentioned message, right?
all of this
nah just the intents part
okay
depends
intents.members = True
bot = commands.Bot(intents=intents)```
basically this @steady thicket
and you have to turn all intents on on your bot's builder page
already done
yeah
if all just use^
and delete those 2 dots and comma
yeah ofc
lol i saw that you kept 'em
delete the second bot = commands...... thingy
cya

from discord import Intents
is that what your doing?
Guys how do I give permission to use the command only to certain roles?
@commands.has_roles() ?
yeah
!d discord.ext.commands.has_role
@discord.ext.commands.has_role(item)```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that is added that checks if the member invoking the command has the role specified via the name or ID specified.
If a string is specified, you must give the exact name of the role, including caps and spelling.
If an integer is specified, you must give the exact snowflake ID of the role.
If the message is invoked in a private message context then the check will return `False`.
This check raises one of two special exceptions, [`MissingRole`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingRole "discord.ext.commands.MissingRole") if the user is missing a role, or [`NoPrivateMessage`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.NoPrivateMessage "discord.ext.commands.NoPrivateMessage") if it is used in a private message. Both inherit from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").
Changed in version 1.1: Raise [`MissingRole`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingRole "discord.ext.commands.MissingRole") or [`NoPrivateMessage`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.NoPrivateMessage "discord.ext.commands.NoPrivateMessage") instead of generic [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure")
oof
@commands.has_role(Role_id)``` @slate swan
gtg later
i think
you are correct lol
LOL
I have it like this as you said
have you programmed in Python before?
because it doesn't seem like it
well, I was mainly watching and learning
but not really
like coded
you can watch python vids, fine, but don't ever watch YT vids about libraries like these
they have many flaws and are way too concrete + incorrect
always will show like that lol
I'll try reinstaling dpy
it will always show like that
how do i convert #252525# (hex) into something that discord.py supports so i can use the hex as the embed color
0x252525
that?
0xhexcode
always like that
delete that bot constructor
no
okay
no need
okay so what next
did you install the discord package or discord.py
Its the same thing
the python one + extra for your config file
dpy use the word discord
it is in fact, not.
how
the discord package from pypi is an outdated mirror
the discord.py package is the correct package
Thx, it's working now
you mean the git version
?
their the same thing dpy in pypi is version 1.7.3 and the one in git is 2.0
no
yes
is usually an outdated mirror
it looks like he pushed 1.7.3, but usually it is outdated
packages don't have to provide a namespace with the same name that they have
for the record, both discord and discord.py have gotten their last pypi updates likely ever
yes... i know
dang
so discord is not usually an outdated mirror if referring to the last 6 months as there haven't been any updates and they're both technically outdated
prize should be before channel
channel should have a default value
channel should be before time1
or that
what I or @cold sonnet said will fix it
That too
this actually won't fix it

it'll change prize being a keyword argument to a positional or keyword argument
wouldnt be needed?
OR channel would need to become a keyword only argument
there would still be a non-default argument after a default one
hmm does that apply for KW only args?
!e ```py
def func(a, b=False, *, c): ...
@vast gale :warning: Your eval job has completed with return code 0.
[No output]
wut
Til this is not the case, if the KW only arg is required it is allowed to not have a default, after a standard arg that DOES have a default
wait nvm
hello @slate swan lol
Hi ! My server is getting raided by some bots, and I noticed that almost all of them have some keywords in their name. let's say bot1 and bot2.
I am currently trying to ban members on join, like this ```py
blacklisted_words = ['bot1', 'bot2']
@commands.Cog.listener()
async def on_member_join(self, member):
await self.bot.wait_until_ready()
logs_channel = self.bot.get_channel(logs_channel_id)
if blacklisted_words in member.display_name.lower():
try:
blusremb = #some text
await member.send(embed=blusremb)
except:
pass
await asyncio.sleep(0.2)
await member.ban(reason="Blacklisted word")
blemb = #some text
await logs_channel.send(embed=blemb)
How can I, instead of defining the `blacklisted_words` list have a command, like `.blword add bot1`...and store them in something simple, like a `blacklisted_words.txt` file that would look like: ```txt
bot1
bot2
?
can you show the code.. ?
are you using something like pycord or disnake ?
yea..but..you still need a discord py library
i'm using a free host for one of my side bots rn..not really powerfull but works for text-bots. if you want i can send you the link in dm
sadly, due to having a lot of work 4 school, i haven't been coding so much since summer, so i don't know how to use buttons either :(
yes, but i use the pycord lib, https://github.com/Pycord-Development/pycord
here you have some examples https://github.com/Pycord-Development/pycord/tree/master/examples/app_commands
wdym ?
yea, but it's still being updated
and has a lot of new features
it's the same as discord.py, just uninstall discord.py and install py-cord
what is the function for member join event?
discord.py died, a lot of other libraries are taking place
on_member_join
as the ones Mihai06 is mentioning above
is it on discord library?
the author of discord.py library decided to quit updating the library
so it is recommended that you find another library
because discord.py is no more
RIP discord.py
yea, rip for the original lib
on_member_join()
takes only one arg thats member
@slate swan ot but u dont talk in jss anymore?
okimii is inactive
just like hunter
they are poor examples of upstanding discord bot coders
what's jss
css but for javascript
huh
Looking for a bit of help
error speaks for itself
just print your banList and you'll see that it doesn't have the "included" key
I have such an erorr when I try to download npm i quick.db
I'm a beginner so a little unattended like something
This is not the JavaScript Discord server :p
how download discord_components? modul
You might want to go in the discord.js server (https://discord.gg/djs) or find a JavaScript related server.
https://discord.gg/programming is a great server imo.
!pypi discord-components
Click on the link and you will see a command to execute at the top :)
there they said that This is not the JavaScript Discord server :p
So I don't know :(
^
or ^ and then go in #244238416248569857
Nevertheless, check this. https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/troubleshooting.md
ok
They will redirect you to the link I sent.
You will have higher chances of getting answers.
hello
Thank you
are there any Turkish people?
I'm pretty sure there are, however this server is English only.
Is it possible to have more then 3 fields inline with discord embeds?
yes, I see
I came because I have an interest in coding
That's nice :D
I can improve my English more thanks to this server.
I'm sure you will find lots of people to talk to in #python-discussion or some of the off topic channels.
This channel is mainly for asking help ^^
I am very sorry
It's okay don't worry, you're new so we can guide you :p
How would I add roles to a member inside a on_raw_reaction_remove?
i got muted๐


smh

payload.member gives an object of the class discord.Member, then you can use .add_roles() on it :)
member is None. That's my issue
Works fine for my on_raw_reaction_add event so its not intents
Is it possible to have more then 3 fields inline with discord embeds?
I personally don't understand it
As they are extremely similar
Anyone got any ideas?
GLOBAL COMMANDS
===============
| NOTE: global commands can take up to 1 hour to show up after registration.
|
| Update is required: False
| To upsert:
| -
| To edit:
| -
| To delete:
| -
| Type migration:
| -
| No changes:
| -
COMMANDS IN 0000000MYGUILDID
==============================
| Update is required: True
| To upsert:
| <SlashCommand name='afk'>,
| <SlashCommand name='invite'>
| To edit:
| -
| To delete:
| -
| Type migration:
| -
| No changes:
| -
/bot-env/lib/python3.9/site-packages/disnake/ext/commands/interaction_bot_base.py:746: SyncWarning: Failed to overwrite commands in <Guild id=000000MYGUILDID> due to 403 Forbidden (error code: 50001): Missing Access
warnings.warn(
DEBUG: Command synchronization task has been finished
``` huh?
I'm using disnake btw
there is no payload.member
in the remove event
!d discord.RawReactionActionEvent
class discord.RawReactionActionEvent```
Represents the payload for a [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") or [`on_raw_reaction_remove()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_remove "discord.on_raw_reaction_remove") event.
but you have an user_id
and a guild_id
so you get the guild by the guild_id
and get the member by user_id in the guild
embed=discord.Embed(title=f"{prize}", description=":tada: reaction to enter!", color=0x00e1ff)
time_numbers = {"s" : 1, "m" : 60, "h" : 3600, "d" : 86400}
give_time = int(time[0]) * time_numbers[time[-1]]
embed.add_field(name="Ends:", value=f"{time}", inline=False)
embed.add_field(name="Hosted by:", value=ctx.author.mention, inline=False)
give_msg = await ctx.send(":tada: **GIVEAWAY** :tada:", embed=embed)
await give_msg.add_reaction(":tada:")
await asyncio.sleep(give_time)
new_msg = await ctx.channel.fetch_message(give_msg.id)
users = await new_msg.reactions[0].users().flatten()
users.pop(users.index(bot.user))
winners = random.choice(users)
await ctx.send(f":tada: Congratulations, {winners.mention} You won **{prize}**!")
em_end=discord.Embed(title=f"{prize}", color=0x00e1ff, timestamp=ctx.message.create_at)
em_end.add_field(name="Hosting By:", value=ctx.author.mention, inline=False)
em_end.add_field(name="Winner(s):", value=winners.mention, inline=False)
em_end.add_field(text="Ended at")
await give_msg.edit(":tada: **GIVEAWAY ENDED!**:tada:", embed=em_end)```
Anyone know why this does not edit my post?
description="":tada: reaction to enter!"
See the issue here?
I tried it does not work.
does any1 know how to make buttons using disnake?
I apologize for the double ping but apparently on_raw_reaction_remove doesn't return a member
from the disnake server:
The Message Reaction Remove event sent by the API doesn't contain member data (unlike Message Reaction Add), so this pretty much works as intended
https://discord.com/developers/docs/topics/gateway#message-reaction-add-message-reaction-add-event-fields
Integrate your service with Discord โ whether it's a bot or a game or whatever your wildest imagination can come up with.
Well I guess back to my original question then
How would I add roles to a member inside a on_raw_reaction_remove?
donโt use discordโs docs. Itโs In JS not Python
so... thats a no.
An api is an api
you can just do get_user on payload.member_id?
user_id*
Because someone earlier was saying it was in JS and I told them to use the librariesโ docs instead
Whats the difference between fetch and get?
no
AttributeError: 'User' object has no attribute 'remove_roles'
member_ = self.bot.get_user(payload.user_id)
Is this correct?
You should probably check the docs before asking @lapis breach
Can anyone help me please?
Do you get any errors?
Yes
^
But it does not seem to me to be related to the editing of the post
Did you fix it?
Fix now
were docs
get() gets the obj in cache and fetch() makes an api call to get the obj
and get is async so no need for await while fetch needs to be awaited
Alright
and another one which disnake has is getch() which it tries to get the obj and if its not found it will fetch it
but thats exclusive to disnake afaik
Is it not called get_or_fetch?
async function are coroutines and they need to be awaited
yeah?
weird people here say it is
but it really doesnt make sense
since coros always need to be awaited
!d disnake.Guild.get_member
get_member(user_id, /)```
Returns a member with the given ID.
Lemme ask my question again, how would I add roles to a member inside a on_raw_reaction_remove event?
disnake/guild.py line 712
def get_channel(self, channel_id: int, /) -> Optional[GuildChannel]:```
idk why people say its async smh
yeah ik
was weird to me cuz how can a function be async and when called they dont await it
Get the member from the payload object and add the role
You are using discord?
The payload has a user and guild ID. First get the guild from the ID, then get the member from the guild using the ID in the payload.
relevant functions are get_guild and get_member
disnake
Ah okay
^
That's what I was trying to do. I guess I was doing it wrong then
Actually
If you share that code then someone might find what is wrong
The member attribute will not work since it's a removal event
I deleted the code and closed my ide
!d disnake.RawReactionActionEvent.member
The member who added the reaction. Only available if event_type is REACTION_ADD and the reaction is inside a guild.
New in version 1.3.
There, the .member attribute returns the Member object who reacted
Only available if event_type is REACTION_ADD and the reaction is inside a guild.
Read the embed
You can add your roles to that
Didn't you want for reaction_add?
Nope
Oh I see, then I misinterpreted
Okay, it's basically member = client.get_guild(payload.guild_id).get_member(payload.user_id). However, note that both those function calls may return None since they rely on the cache. get_member is more likely to fail for that reason, and also because the member might have left the guild.
To get around the cache issues, there's fetch_member and fetch_guild which you could fall back to if the get_ methods return None
They are API calls and need to awaited
Not sure if you're familiar with disnake but there is a function called getch that does that automatically I think
By that I'm referring to calling the API if fetching the member fails
Hello!! newbie here... im looking for a script that can sent a text line from a file to discord.. everything i try failed sofar.. can anyone point me in the right direction
getch just merges both
docs
!d discord.File
class discord.File(fp, filename=None, *, spoiler=False)```
A parameter object used for [`abc.Messageable.send()`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable.send "discord.abc.Messageable.send") for sending file objects.
Note
File objects are single use and are not meant to be reused in multiple [`abc.Messageable.send()`](https://discordpy.readthedocs.io/en/master/api.html#discord.abc.Messageable.send "discord.abc.Messageable.send")s.
when you call getch method, it first looks up in cache and if that returns None
It makes an API call using fetch
await getch_user(user_id, *, strict=False)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Tries to get the user from the cache. If fails, it tries to fetch the user from the API.
!d disnake.Client.get_or_fetch_user
await get_or_fetch_user(user_id, *, strict=False)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Tries to get the user from the cache. If fails, it tries to fetch the user from the API.
Whats the difference between these 2?
get is a cache call and fetch is a raw API call, get doesn't need to be awaited, fetch needs to be awaited
yo why doesn't this return any output? py @commands.Cog.listener() async def on_reaction_add(self, reaction, user): if user == bot.user: #returning if the bot reacts return else: if reaction.emoji == "โ
": #checking if there is reaction print("hello")
I'm not familiar with it, but if you have that, then sure you can use it instead.
How would I add a counter to this to post how many minutes the bot has been up for? I'm not very familiar with running synchronous functions
Wondering if i can just add this somehow
counter = 0
while true:
counter+=1
print(counter)
time.sleep(60000)```
```python
import os
import discord
from discord.ext import commands
import random
bot = commands.Bot(command_prefix = '.')
@bot.event #posts that bot is running
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
emojis =[
"\u0033\u20E3",
"\u0031\u20E3",
"\u0039\u20E3"]
dan = redacted
@bot.event
async def on_message(message):
if(message.author.id == dan):
for emoji in emojis:
await message.add_reaction(emoji)
else:
pass
bot.run('redacted')```
time.sleep would block your bot
fully
youll have to add a task loop
Oh as simple as this?
@tasks.loop(seconds = 10) # repeat after every 10 seconds
async def myLoop():
# work```
idk im not very familiar with them either
I'll give it a try tyty
wait what are you trying to do?
kinda confused
cuz if you want to keep track of your bots run time idk if a task can help
how do I read information on an embed?
embed.footer
i dont think thats what he wants do
i think he wants to check text in a embed
reading information on an embed
lol
yeah how do I do it
with your eyes
How would I read the discord id off an embed my bot creates
discord id?
yeah
ill show you
how to check if member is mentioned or not? (for a ban command)
you mean set the id?
<@id>?
and thats a user id iirc
you take it out?
like how do I get the user id of that embed
no just like get it assigned to a variable
if member:
how to check if member is mentioned or not? (for a ban command)
you got an idea?
may u explain more pls im kinda brain dead rn
if member.mentioned == True:
<code here>
?
so
not sure confused lol
if member:
<code here>
```?
okay I want to get the id of the user so I can use it in another function
Can I see your code?
no hes checking if the member arg has been mentioned i think
Ah
Why would you want to do that?
ig get the msg
you check the msgs content
okay how do I find the field
You can just type hint it to a discord.Member object
@commands.command()
async def ban(self, ctx, member: disnake.Member):
if ctx.message.author.guild_permissions.administrator == False:
embed = disnake.Embed(title="You can't use this command!", description=":cancel: Only **Admins** and up can use this command!")
await ctx.send(embed = embed)
if ctx.message.author.guild_permissions.administrator == True:
embed = disnake.Embed(title="Ban Result:", description="")
await ctx.send("In Development")
if member.mentioned == True:
code
yeah it would take id or mention
^
since it takes the id from the mention
No documentation found for the requested symbol.
@final iron
ik that
Not true
i think it shows all raw text
im just using the other way it works
!e ```py
foo = 100
if foo:
print("A")
if foo == True:
print("B")
@pliant gulch :white_check_mark: Your eval job has completed with return code 0.
A
@final iron
Alright. Why do you want to check if a member was mentioned?
to make a invalid usage code
itll tell them how to use the command if they dont mention a user
!d discord.Member.mentioned_in
mentioned_in(message)```
Checks if the member is mentioned in the specified message.
? @final iron
^
is there a easier way?
I don't see how thats difficult
Oh, didn't know the context here
but your in a command so
Just give member a default value, E.g None
Inside of the command's callback check if member is None
If it is, they didn't mention or supply a member
cant i just do
i think they want to check if the user added a id or a mention
if ctx.message.mentions:
<code here>
A list of Member that were mentioned. If the message is in a private message then the list will be of User instead. For messages that are not of type MessageType.default, this array can be used to aid in system messages. For more information, see system_content.
Warning
The order of the mentions list is not in any particular order so you should not rely on it. This is a Discord limitation, not one with the library.
Yea, they have an argument for it
typehinted to Member
So if you give it a default value, and they don't pass a member arg
It will be None, so just check
I got my bot to join my vc, is there a way to make it infinitely repeat a voice clip?
You could put your play inside a loop where you check if VoiceClient.is_playing() is True, if it is continue the loop. Otherwise if is_playing() is False that would mean the bot has stopped playing the clip, so just do play again if it is False
yea i was just gonna do a while loop
but how do you even make the bot play something?
whether it be a youtube video, or a voiceclip saved locally on your pc?
!d discord.VoiceClient.play
play(source, *, after=None)```
Plays an [`AudioSource`](https://discordpy.readthedocs.io/en/master/api.html#discord.AudioSource "discord.AudioSource").
The finalizer, `after` is called after the source has been exhausted or an error occurred.
If an error happens while the audio player is running, the exception is caught and the audio player is then stopped. If no after callback is passed, any caught exception will be displayed as if it were raised.
Try not to play youtube videos though
Why?
That's against Youtubes ToS
A few big bots that have that feature have been taken down via DMCA
Oh dang, it can play a voiceclip saved locally on your pc right?
Depends ยฏ_(ใ)_/ยฏ
If its a locally downloaded music you need the licensing
If it's just a voice clip you should be fine, might need permission from the person who the voice clip is from though
no as long as your bot doesn't get popular you're perfectly fine
if it does then take precautions
Basically saying, "lets break the law we won't get in trouble if no one finds out"
you're breaking TOS not the law
ToS is an agreement/contract you agree to
Isn't that legally binding?
Otherwise if it isn't against the law, they will just sue you or send a DMCA
usually it's DMCA
and yeah
ive never done it before but im sure there's a way around
Checked, it is legally binding
relax it'll be a voiceclip of me
So yes if you break ToS your breaking the law
through remixes etc
good luck w your project
I power my bot through a virtual machine though. I can't save the voiceclip locally and use it. I'll have to save it on the virtual machine itself somehow and link if from there
Upload the voice clip to a file host and download it from the virtual machine
you can use a VPS for that
Otherwise use a file transport protocol
no just put the mp3 in a folder along with your bot source
Yea, so you'd need to put it on a file host or ftp it
to get a bot to respond to you when you mention it, its commands.when_mentioned_or in dpy but what is it in hikari-lightbulb?
They said VM not VPS so I'm going off what they said
Either way to transfer your mp3 to the VPS you need to file host it or ftp it again lmao

how do i call that start() thing? i dont rrl know what i am doing
k then...
thats right
Heyy, I'm trying to make a somewhat useless BOT and need some help with how. I want the BOT to just count endlessly, How can I do so?
@bot.command()
async def timeout(ctx, member: disnake.Member, time: float = None, *, reason=None) -> None:
await member.timeout(duration=time, reason=reason)
for each msg add a value to a var and send the var
yw
Do I make it an event command or just command?
Pretty much just want to start it and it should keep counting
forever like count on it self?
yes
a = range(1, 100000001)
for b in a:
await ctx.send(b)
await asyncio.sleep(1.5)
or add it to a while loop and add a int to a var
which is probably better
a = 0
while True:
await ctx.send(a)
a += 1
await asyncio.sleep(5.0)
This would not count at all
wdym
Oh heyy, I'm back
wdym?
Oh dam. How can I do it then Andy? or Okimii
kinda confused
You define a inside of the loop, thus it will make a 0
oh yeah your right
if you do this, you're just asking to get ratelimited
ik lol
So what should I do?
^ this maybe
i added allot of time lol
explain?
One time they could be 5/5s, another time they can be 10/5s
ah i see
import asyncio
a is a local var now
done
Unless that's what you want




