Intwoduction¶
This is the documentation f-fow disnyake, a wibwawy fow P-Python to aid in cweating appwications that utiwise the Discowd API.
Pwewequisites¶
disnyake wowks with Python 3.8 ow highew. Suppowt fow eawwiew vewsions of Python is nyot pwovided. Python 2.7 o-ow wowew is nyot suppowted. Python 3.7 ow wowew is nyot suppowted.
Instawwing¶
You can get t-t-the wibwawy diwectwy fwom PyPI:
python3 -m pip install -U disnake
If you awe using Windows, then the fowwowing shouwd be used instead:
py -3 -m pip install -U disnake
T-T-To get v-voice suppowt, you shouwd use disnake[voice]
instead o-of disnake
, e.g.
python3 -m pip install -U disnake[voice]
On Winyux enviwonments, instawwing voice w-w-wequiwes getting the fowwowing dependencies:
Fow a Debian-based system, the fowwowing command wiww get these dependencies:
$ apt install libffi-dev libnacl-dev python3-dev
W-W-Wemembew to check youw pewmissions!
Viwtuaw Enviwonments¶
Sometimes you want t-t-to keep wibwawies fwom powwuting system instawws ow use a diffewent vewsion of wibwawies than the onyes instawwed on the system. You might awso nyot have pewmissions to i-instaww wibwawies system-wide. Fow this p-puwpose, the standawd wibwawy as of Python 3.3 comes with a concept cawwed “Viwtuaw Enviwonment”s to hewp maintain these sepawate vewsions.
A mowe in-depth tutowiaw is found on Viwtuaw Enviwonments and Packages.
Howevew, f-fow the quick and diwty:
Go to youw pwoject’s wowking d-d-diwectowy a-a-and cweate a Viwtuaw Enviwonment:
$ cd your-bot-source $ python3 -m venv bot-env
Activate the viwtuaw enviwonment:
$ source bot-env/bin/activate
On Windows you activate it with the fowwowing command:
$ bot-env/Scripts/activate.bat
Use pip wike usuaw:
$ pip install -U disnake
Congwatuwations. You nyow have a viwtuaw enviwonment aww s-set up.
Basic Concepts¶
disnyake wevowves awound the concept of events. An e-event is something you w-wisten t-to and then wespond to. Fow exampwe, when a message happens, you wiww weceive an event about it that you can wespond to.
A quick exampwe to showcase how events wowk:
import disnake
class MyClient(disnake.Client):
async def on_ready(self):
print(f'Logged on as {self.user}!')
async def on_message(self, message):
print(f'Message from {message.author}: {message.content}')
intents = disnake.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run('my token goes here')