Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.5k stars 3.74k forks source link

Lack of a tutorial for writing a client using bot-style code #2340

Open Ivoz opened 4 years ago

Ivoz commented 4 years ago

Currently the docs contain a small example for writing a discord client using just the client object;

But there is no comparable analogue if someone wants to write a specifically a "bot", and make use of the Bot / Cog infrastructure.

The docs immediately get into the weeds of writing commands, but there is no preparatory section for how to get started laying out a simple file / application using this style.

A short guide laying out how the code for basic_bot.py is structured (is that up to date?) would likely suffice; or even pointing to it in the docs as a pre-emptive start.

hammy275 commented 4 years ago

I know practically no knowledge of using cogs as I haven't messed around with them yet but writing a bot instead of client is basically just replacing every instance of the word "client" with the word "bot". For example, in the basic_bot.py you linked, it uses @bot.event on line 11 instead of @client.event. The key to this is the fact that the bot variable is named bot, as shown on line 9 of basic_bot.py.

Bluenix2 commented 4 years ago

Bot is a subclass of client. So anything you can do with client you can do with bot. Now, bot does add the cog, command, and check features. So you can use the client tutorials with bot. There are also sepperate tutorials for creating commands which are well made (not in examples ). And for nearly all other external features. If you scroll down in the documentation you'll find the ext section where all bot stuff are located.

Ivoz commented 4 years ago

Explanations don't need to be in this issue thread, or on a blog that will one day be out-of-date, or a youtube video, they need to be in a doc page somewhere.

And yes the Extensions section is somewhat thorough, but rarely holistic, or looking from the big picture. There is no starting point; only immediate weeds to wade through.

I posted this thread because I was looking for such a page to give to someone hoping to start with discord.py, and I had the assumption that "for most cases it's probably more useful for someone writing a bot to jump to the bot/commands API straight away" but a jumping off point for this case is not currently present.

Vexs commented 4 years ago

This library has overall needed a prose/concept guide for some time. There is a start guide for just building a bot which, as you note, doesn't showcase commands ext and frankly I'm somewhat curious how many people have read. Given this library's high percentage of novice users, it could probably be hard-pointed more and expanded.
There technically is an example of using commands.ext in the docs, readme.rst has one, but it's lightweight (as a readme should be) and only "visible" on the github. In fact, after searching the docs the examples directory is mentioned once in the readme, and only directly linked in the FAQ entry for how to do a task in a loop.

Anyway, I don't think you'll find too much disagreement that a how-to-chain is needed, this library has a number of little pitfalls you can fall into leading to suboptimal performance. (fetch vs get is my preferred example, but theres a note on that now) Unfortunately, writing good tutorial/prose/concept documentation is nontrivial and difficult. There are also a number of questions as for how far it should cover, should it include common bot features, etc? There was a survey done a while back about this and it's been fairly extensively discussed in the discord server, but it still needs someone to write it.