Python: Making a Discord bot (Part 12: Server Prefixes)

Python: Making a Discord bot (Part 12: Server Prefixes)

Lucas

4 года назад

98,256 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Lucas-tz3jp
@Lucas-tz3jp - 06.12.2020 22:23

Hey guys! Glad to see everyone loved the series. For those of you who want more support or need help with other bot related topics not covered in this series, I have an invite link to my discord server in the description. There are lots of people there who are willing to help you and I myself am still active as I periodically pop in to chat! Hope to see you there :)

Ответить
@user-xt9hx1bw5r
@user-xt9hx1bw5r - 07.07.2023 12:36

Thanks, for this. Question, how do you refer to a servers (guilds) prefix in another command like a help command. for example when you run the help command it does: ctx.send(f"Your prefix is {prefix}")?

Ответить
@Nick-cm7jf
@Nick-cm7jf - 13.08.2022 18:55

I still don't understand, what is hikari? I just want to code and not have to download so much stuff.

Ответить
@AntonisRsmn
@AntonisRsmn - 11.07.2022 06:57

Can anyone help me pls
So im making a discord bot and i add the custom prefix but i have some trouble to add it to modules i mean i have a command when you mention the bot the bot will send the prefix and i want to send the custom prefix does anyone help with this because i have tried and i cant figure it out and if its simple pls tell me

Ответить
@No_Name59
@No_Name59 - 21.06.2022 11:42

Now the Russian-speaking discord servers is a bastard habitat.discord server does not play any role.only from the occupancy of the bastard himself.

Ответить
@omgitsgod1
@omgitsgod1 - 17.05.2022 06:22

hey can u show how to make a bot leave a server with a command

Ответить
@gdkid
@gdkid - 07.02.2022 09:50

Make sure to add a fallback in get_prefix in case for whatever reason the server isn't in the prefixes.json file, you can just try except the whole thing, and in the except block, just return the default prefix (in this case the "."), so like this

def get_prefix(client, message):
if not message.guild: # DMs go by user IDs rather than a "DM ID" of some sort
return "."

try:
with open("./prefixes.json", "r") as f:
prefixes = json.load(f)

return prefixes[str(message.guild.id)]

except Exception: # Somethings gone wrong
return "."

Ответить
@shivjotjosan2913
@shivjotjosan2913 - 19.01.2022 05:10

thx for given me a good bot and making me learn how to make my own

Ответить
@abhinavsai1654
@abhinavsai1654 - 27.10.2021 10:50

This absolutely works. Thanks for the video. Very simple and readable code. Thanks a lot man! Beautiful video!!

Ответить
@bourkupine1281
@bourkupine1281 - 14.09.2021 20:13

you are moving along wayyy to quickly

Ответить
@zeffdebunked1072
@zeffdebunked1072 - 09.09.2021 02:04

this man is a legend

Ответить
@akopaaa
@akopaaa - 03.09.2021 01:14

Exellent video thanks !

Ответить
@qfuza9512
@qfuza9512 - 23.08.2021 16:02

WHY ARE U SUDDDENLY JOINING THE DARK SIDE WITH JSON LMAOAOAAOAOOAA

Ответить
@TheDarkSideOP
@TheDarkSideOP - 17.08.2021 12:36

def get_prefix(bot, message):
with open(prefixes.json', 'r') as f:
prefixes = json.load(f)

return prefixes[str(message.guild.id)]

Ответить
@themessifan1785
@themessifan1785 - 29.07.2021 21:02

It worked YAY, well I shouldn't be surprised all of Lucas's tutorials work

Ответить
@ShaLanGi
@ShaLanGi - 18.07.2021 13:28

how to pull prefix on status?

Ответить
@abirshandilya8513
@abirshandilya8513 - 18.07.2021 11:21

he's recording at 12:28am OP

Ответить
@dalaricj.i6954
@dalaricj.i6954 - 04.07.2021 08:24

Thank you, you make my bot cooler right now. I really thank you to you. Again, really-really thank you

Ответить
@Kiltoch
@Kiltoch - 01.07.2021 00:24

What color theme are you using?

Ответить
@scaredspike6290
@scaredspike6290 - 22.06.2021 10:45

with open("prefixes.json", "w") as f:
json.dump(prefixes,f , indent-4)

Ответить
@NotAestheticallyDucko
@NotAestheticallyDucko - 16.06.2021 20:47

i love this i love uu bc you helped me to start a discord bot

Ответить
@WildDred
@WildDred - 11.06.2021 16:09

i tried several times and the result is still the same

FileNotFoundError: [Errno 2] No such file or directory: 'prefixes.json'

i've tried using absolute path but it doesnt work for me, any solution?

Ответить
@catlayingonmywindow9508
@catlayingonmywindow9508 - 27.05.2021 16:11

Thanks Lucas!

Ответить
@ignasskarzinskas7126
@ignasskarzinskas7126 - 17.05.2021 09:48

i cant get the bot to write in the .json file

Ответить
@nipun5190
@nipun5190 - 13.05.2021 13:40

hey, can anyone tell me how to keep a bot online 24/7 ?

Ответить
@DenRoblox
@DenRoblox - 27.04.2021 11:12

how to make the server prefixes appear in front of the command names in the "help" command?

Ответить
@bugrahankaya5137
@bugrahankaya5137 - 24.04.2021 16:36

Can you make a video about join/leave 2020

Ответить
@aahilsalt
@aahilsalt - 13.04.2021 21:22

hey @Lucas, I had some questions, and I know that this is a bit late, as you said that you finished your series, but can you please make some tutorials for adding a reaction-role system, music, and an economic system, in the rewrite version, please! I know that music is in your old tutorial, but I've made like 400 lines of code, all in the rewrite version, so can you please make tutorials for those? Btw, epic series, really cool, and I wish I had found your channel earlier! You just gained a sub!

Ответить
@icodeonpython5656
@icodeonpython5656 - 08.04.2021 13:48

u got +1 sub. Nice tutorials!

Ответить
@BJ_Gaming2
@BJ_Gaming2 - 02.04.2021 08:52

What About Making a Verify Command that You Only Use ".verify" and the Bot Will Add a Verified Role to Whoever Sent the Command

Ответить
@Techny
@Techny - 26.03.2021 18:29

Loved The Series💖

Ответить
@uPrimal
@uPrimal - 20.03.2021 19:39

Does anyone know why I get this error?
NameError: name 'prefixes' is not defined

I practically copied the entire code from the video but no matter what I do 'prefixes' is still not defined apparently.

Ответить
@TheRapidDev
@TheRapidDev - 09.03.2021 06:02

Guys, I would include this line: @commands.has_permissions(administrator=True) right after the @client.commands (aka on the next line, right before the async) to make sure only people with the admin permission can change the bots prefix. Nothing much but it goes a long way trust me.Hope this helped :)

Ответить
@n3k0chka
@n3k0chka - 08.03.2021 01:14

I have problem on return prefixes[str(guild.id)] = "-" (Invalid Syntax =)

Ответить
@ae-co5ue
@ae-co5ue - 05.03.2021 15:30

prefixes.pop(str(guild.id)) = '.'
^
SyntaxError: cannot assign to function call

anyone know how to fix this?

Ответить
@itsmaxplayz6498
@itsmaxplayz6498 - 20.02.2021 18:26

it gives me an error that I am missing two arguements client and message when I call the get_prefix() function in commands.Bot(command_prefix=get_prefix()) line

Ответить
@sheez-5486
@sheez-5486 - 17.02.2021 09:10

i still can't believe that i finished this awsome series in two days, Thank you, but we want more...

Ответить
@SimplyCode
@SimplyCode - 12.02.2021 15:22

please can you make a video on music bot
the old one doesn't work!!!

Ответить
@poisonouspotato8303
@poisonouspotato8303 - 11.02.2021 19:53

Ok, firstly thanks for the help! My bot works perfectly fine!
Anyways, how can I delete the command usage after I have done the command?
Like, if type .hello the bot responds with Hi, but the ".hello" coammand is still there! What can I do to fix it?

Ответить
@jaymilee2575
@jaymilee2575 - 08.02.2021 14:15

image banning someone cause they rejoined a server, what a neek

Ответить
@jaymilee2575
@jaymilee2575 - 08.02.2021 14:14

worst moderator in town

Ответить
@jaymilee2575
@jaymilee2575 - 08.02.2021 14:01

Jaxtar is some nerd

Ответить
@marcelrieger5182
@marcelrieger5182 - 01.02.2021 00:30

Can you show how to make a music bot?

Ответить
@Magnum69
@Magnum69 - 30.01.2021 23:02

Don't know if you're planning on making a new video but this is a great video idea I think:
Custom Help command!

Ответить
@krishna20071
@krishna20071 - 28.01.2021 20:01

Can this work if your using discord on a browser cuz I haven’t downloaded it

Ответить
@Madbrad2000
@Madbrad2000 - 17.01.2021 12:55

It's important to note that if you do this, your bot will not work anymore in DM's because it won't have a prefix for direct messages/private messages (by default, all bots work in PM).

Pretty simple to fix though, just add the 'if not message.guild' bit to get_prefix (replace "?" with whatever you want your default prefix to be). Make sure to add 'message' to the arguments.

def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)

if not message.guild: # if in dms
return commands.when_mentioned_or("?")(client, message)

Ответить