mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-12-18 05:03:28 +00:00
스킵 구현
This commit is contained in:
17
DPP-master/docpages/make_a_bot/clion.md
Normal file
17
DPP-master/docpages/make_a_bot/clion.md
Normal file
@@ -0,0 +1,17 @@
|
||||
\page build-a-discord-bot-linux-clion Building a Discord Bot using CLion (Linux)
|
||||
|
||||
\warning **This tutorial assumes you are using Ubuntu**. You might use other distros if you prefer, but keep in mind the setup process might be different! This tutorial also teaches you how to use DPP with CMake, using the JetBrains IDE **[CLion](https://www.jetbrains.com/clion/)**. If you have not installed CLion, You can [download CLion here](https://www.jetbrains.com/de-de/clion/download/). If you do not have DPP installed, visit \ref buildcmake "this page" on how to setup the project using a precompiled version of DPP. If you want to use source and haven't set that up, look towards \ref buildlinux "this page" on how to do so. **This tutorial will not teach you how to setup CMake and will assume you have already done so**.
|
||||
|
||||
### Add an example program
|
||||
|
||||
Open up CLion and open the folder for your bot. You may notice that CLion will start doing the whole CMake process and it will create a folder called `cmake-build-debug`, this is normal so don't be alarmed! It is just CLion registering all the CMake stuff so it can build and give you auto-suggestions.
|
||||
|
||||
Now, you can open your `main.cpp` file. If you have code there, then you're one step ahead! If not, copy and paste the following \ref firstbot "example program" in the `main.cpp` and set your bot token (see \ref creating-a-bot-application). Here's how your `main.cpp` file should look:
|
||||
|
||||
\include{cpp} firstbot.cpp
|
||||
|
||||
Now, you can go ahead and hit the green "Run" button in the top-right to run the bot.
|
||||
|
||||
**Congratulations, you've successfully set up a bot!**
|
||||
|
||||
If you're stuck, come find us on the [official discord server](https://discord.gg/dpp)! Ask away! We don't bite!
|
||||
129
DPP-master/docpages/make_a_bot/cmake.md
Normal file
129
DPP-master/docpages/make_a_bot/cmake.md
Normal file
@@ -0,0 +1,129 @@
|
||||
\page buildcmake Building a Discord Bot Using CMake (UNIX)
|
||||
|
||||
\warning **This tutorial will assume that you have already installed DPP.** If you haven't, please head over to \ref install-linux-deb "this page", or any install page that matches your OS. If you want to use source, then continue your journey over at \ref buildlinux "this page" for a full explanation into using CMake with source.
|
||||
|
||||
## 1. Toolchain
|
||||
Before continuing, you will need to install `cmake` on your system. To be sure that `cmake` is installed, you can type the following command:
|
||||
|
||||
```bash
|
||||
$ cmake --version
|
||||
cmake version 3.22.1
|
||||
```
|
||||
|
||||
If your CMake version is not as shown above then don't worry! You can still follow along, even if you're ahead or behind!
|
||||
|
||||
## 2. Create a CMake project
|
||||
|
||||
In an empty directory, create the following files and directories:
|
||||
|
||||
\dot
|
||||
digraph "Example Directory" {
|
||||
graph [ranksep=1];
|
||||
node [colorscheme="blues9", fontname="helvetica"];
|
||||
|
||||
"Your Directory" [style=filled, color=1, shape=rect]
|
||||
|
||||
subgraph cluster_0 {
|
||||
style=filled;
|
||||
color=lightgrey;
|
||||
node [style=filled, color=2, shape=rect]
|
||||
build;
|
||||
cmake;
|
||||
src;
|
||||
"CMakeLists.txt";
|
||||
label = "The main area for your bot's files.";
|
||||
}
|
||||
|
||||
subgraph cluster_1 {
|
||||
style=filled;
|
||||
color=lightgrey;
|
||||
node [style=filled, color=3, shape=rect]
|
||||
"FindDPP.cmake";
|
||||
label = "This file is to tell CMake where DPP is.";
|
||||
}
|
||||
|
||||
subgraph cluster_2 {
|
||||
style=filled;
|
||||
color=lightgrey;
|
||||
node [style=filled, color=3, shape=rect]
|
||||
"main.cpp";
|
||||
"main.h";
|
||||
"more code...";
|
||||
label = "This is where your bot's code will go.";
|
||||
}
|
||||
|
||||
"Your Directory" -> build;
|
||||
"Your Directory" -> src;
|
||||
"Your Directory" -> cmake;
|
||||
"Your Directory" -> "CMakeLists.txt";
|
||||
|
||||
cmake -> "FindDPP.cmake";
|
||||
|
||||
src -> "main.cpp";
|
||||
src -> "main.h";
|
||||
src -> "more code...";
|
||||
}
|
||||
\enddot
|
||||
|
||||
## 3. Configure CMake
|
||||
|
||||
You'll need to modify the `CMakeLists.txt` to tell CMake what it's looking for, and other information.
|
||||
|
||||
Here is an example CMake configuration, you can adapt it according to your needs:
|
||||
|
||||
~~~~~~~~~~~~~~cmake
|
||||
# Minimum CMake version required, we'll just use the latest version.
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
# Project name, version and description
|
||||
project(discord-bot VERSION 1.0 DESCRIPTION "A discord bot")
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
# Create an executable
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/main.cpp
|
||||
)
|
||||
|
||||
# Find our pre-installed DPP package (using FindDPP.cmake).
|
||||
find_package(DPP REQUIRED)
|
||||
|
||||
# Link the pre-installed DPP package.
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${DPP_LIBRARIES}
|
||||
)
|
||||
|
||||
# Include the DPP directories.
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${DPP_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
# Set C++ version
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
We'll also need to populate our `FindDPP.cmake` file, inside the `cmake` directory!
|
||||
|
||||
Here's what you should use:
|
||||
|
||||
~~~~~~~~~~~~~~cmake
|
||||
find_path(DPP_INCLUDE_DIR NAMES dpp/dpp.h HINTS ${DPP_ROOT_DIR})
|
||||
|
||||
find_library(DPP_LIBRARIES NAMES dpp "libdpp.a" HINTS ${DPP_ROOT_DIR})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package_handle_standard_args(DPP DEFAULT_MSG DPP_LIBRARIES DPP_INCLUDE_DIR)
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
## 4. Build the bot.
|
||||
|
||||
Now that we have our all our cmake stuff setup and we've got our code in place, we can initalise CMake. You'll want to go inside the `build/` directory and do `cmake ..`.
|
||||
|
||||
Once that's completed, you'll want to head back to your up-most folder (where all the folders are for your bot) and run `cmake --build build/ -j4` (replace -j4 with however many threads you want to use). This will start compiling your bot and creating the executable.
|
||||
|
||||
After that has finished, you can head into `build/` and run your bot by doing `./discord-bot`! If everything went well, you should see your bot come online!
|
||||
|
||||
**Have fun!**
|
||||
66
DPP-master/docpages/make_a_bot/meson.md
Normal file
66
DPP-master/docpages/make_a_bot/meson.md
Normal file
@@ -0,0 +1,66 @@
|
||||
\page buildmeson Build a Discord Bot Using Meson
|
||||
|
||||
## 1. Toolchain
|
||||
|
||||
Before compiling, you will need to install `meson` on your system. To be sure that `meson` is installed, you can type the following command:
|
||||
|
||||
```bash
|
||||
meson --version
|
||||
0.63.2
|
||||
```
|
||||
|
||||
## 2. Create a Meson project
|
||||
|
||||
First, you'll need to go ahead and create an empty directory, we'll call it `meson-project`.
|
||||
|
||||
Then, run this command:
|
||||
|
||||
```bash
|
||||
meson init -l cpp
|
||||
```
|
||||
|
||||
## 3. Configuring Your Meson Project
|
||||
|
||||
Add the following line after the `project()` line in your `meson.build` file.
|
||||
|
||||
```yml
|
||||
dpp = dependency('dpp')
|
||||
```
|
||||
|
||||
Add the following line in the executable section of your `meson.build` file.
|
||||
|
||||
```yml
|
||||
dependencies: [dpp]
|
||||
```
|
||||
|
||||
Change the `cpp_std` value in the `project()` to `c++17`. Your `meson.build` should look like this:
|
||||
|
||||
your meson.build should look like this.
|
||||
~~~~~~~~~~~~~~yml
|
||||
project('discord-bot', 'cpp',
|
||||
version : '0.1',
|
||||
default_options : ['warning_level=3',
|
||||
'cpp_std=c++17'])
|
||||
|
||||
dpp = dependency('dpp')
|
||||
|
||||
exe = executable('discord', 'discord_bot.cpp',
|
||||
install : true, dependencies: [dpp])
|
||||
|
||||
test('basic', exe)
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Meson automatically generates a cpp for your project. And a test suite.
|
||||
|
||||
## 4. Building
|
||||
|
||||
To build a Meson project, run the following:
|
||||
|
||||
```bash
|
||||
meson setup builddir
|
||||
meson compile -C builddir
|
||||
```
|
||||
|
||||
Now, your Meson project should be all setup!
|
||||
|
||||
**Have fun!**
|
||||
45
DPP-master/docpages/make_a_bot/replit.md
Normal file
45
DPP-master/docpages/make_a_bot/replit.md
Normal file
@@ -0,0 +1,45 @@
|
||||
\page building-a-cpp-discord-bot-in-repl Creating a Discord Bot in Replit
|
||||
|
||||
\warning Be aware, Replit changes frequently, meaning DPP may not always work. It is out of our control and you simply have to hope that they change it again. If this is an inconvenience, we recommend you obtain some affordable non-free hosting.
|
||||
|
||||
\note There is a premade repl, ready for use, which was built using the steps below. If you wish to use this repl simply [visit this GitHub repository](https://github.com/alanlichen/dpp-on-repl) and click the "Run on Replit" button. Then, follow the steps in the README file.
|
||||
|
||||
To build a D++ bot in a Replit instance, follow these steps. These steps are slightly more convoluted than installing D++ into a standard container as we don't have access to root in the conventional way or write access to any files outside of our home directory in a repl. This guide sidesteps the issue by locally extracting a `libdpp` deb file installer, and referencing the local dependencies from the command-line.
|
||||
|
||||
1. Use wget, or the upload button, to get the precompiled x64 release into your repl as a file, e.g. `wget -O libdpp.deb https://dl.dpp.dev/latest`,
|
||||
2. Extract this deb file using `dpkg`:
|
||||
```bash
|
||||
dpkg -x libdpp.deb .
|
||||
```
|
||||
3. Compile your bot, note that you should be sure to include the `pthread` library explicitly and reference the extracted dpp installation you just put into the repl:
|
||||
```bash
|
||||
g++ -o bot main.cpp -ldpp -lpthread -L./usr/lib -I./usr/include -std=c++17
|
||||
```
|
||||
4. Run your bot! Note that you will need to set `LD_PRELOAD` to reference `libdpp.so` as it will be located in `$HOME` and not `/usr/lib`:
|
||||
```bash
|
||||
LD_PRELOAD=./usr/lib/libdpp.so ./bot
|
||||
```
|
||||
|
||||
Now that your bot is running, you have to keep it online. Replit automatically puts repls to sleep after some time, so you will need to ping a webserver. Unfortunately, Replit is sometimes limiting, and this is one of the only free workarounds to this issue.
|
||||
|
||||
1. Start a http server. This can be through any webserver, but as a simple solution, use python's built in http.server:
|
||||
```bash
|
||||
python3 -m http.server
|
||||
```
|
||||
2. Create an `index.html` file with anything inside it for the server to serve.
|
||||
3. Go to [uptimerobot.com](https://uptimerobot.com/) and create an account if you don't have one.
|
||||
4. After verifying your account, click "Add New Monitor".
|
||||
+ For Monitor Type, select "HTTP(s)"
|
||||
+ In Friendly Name, put the name of your bot
|
||||
+ For your URL, copy the URL of the new website that repl is serving for you
|
||||
+ Select any alert contacts you want, then click "Create Monitor"
|
||||
|
||||
Here is an example of a possible uptimerobot configuration:
|
||||
|
||||
\image html uptimerobot.png
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- If the bot fails to start and instead you receive an error message about being banned from the Discord API, there is little to be done about this. These bans are temporary but because Replit is a shared platform, you share an IP address with many thousands of bots, some abusive and some badly written. This will happen often and is outside of the control of yourself and us. However, you can try to mitigate this by typing `kill 1` in the shell. This is not guaranteed to work, and you might need to try it a few times. If it still does not work, then we recommend you obtain some affordable non-free hosting instead.
|
||||
|
||||
- If your bot continues to fall asleep even though you have a server, we advise you to double check that no errors are happening, and if the server is being pinged. If that still does not work then, again, we recommend you obtain some affordable non-free hosting.
|
||||
40
DPP-master/docpages/make_a_bot/token.md
Normal file
40
DPP-master/docpages/make_a_bot/token.md
Normal file
@@ -0,0 +1,40 @@
|
||||
\page creating-a-bot-application Creating a Bot Token
|
||||
|
||||
Before you start coding, you need to create and register your bot in the Discord developer portal. You can then add this bot to your Discord server.
|
||||
|
||||
## Creating a New Bot
|
||||
|
||||
To create a new application, take the steps as follows:
|
||||
|
||||
1. Sign in to the [Discord developer portal](https://discord.com/developers/applications) and click on "New Application" on the top right.
|
||||
2. Next, enter a name for the application in the pop-up and press the "Create" button.
|
||||
\image html create_application_confirm_popup.png
|
||||
In this example we named it "D++ Test Bot".
|
||||
3. Move on by click the "Bot" tab in the left-hand side of the screen. Now click the "Add Bot" button on the right and confirm that you want to add the bot to your application.
|
||||
\image html create_application_add_bot.png
|
||||
On the resulting screen, you’ll note a page with information regarding your new bot. You can edit your bot name, description, and avatar here if you want to. If you wish to read the message content from messages, you need to enable the message content intent in the "Privileged Gateway Intents" section.
|
||||
\image html create_application_bot_overview.png
|
||||
In this panel, you can get your bot token by clicking "Reset Token". A bot token looks like this: `OTAyOTMxODU1NTU1MzE3ODUw.YXlm0g.9oYCt-XHXVH_z9qAytzmVRzKWTg`
|
||||
|
||||
\warning **Do not share this token** with anybody! If you ever somehow compromise your current bot token or see your bot in danger, you can regenerate the token in the panel.
|
||||
|
||||
## Adding the Bot to Your Server
|
||||
|
||||
Once you've created your bot in the discord developer portal, you may wonder:
|
||||
|
||||
> Where is my bot now, I can't see him on my server?!
|
||||
|
||||
That's because you've created a bot application, but it's not on any server right now. So, to invite the bot to your server, you must create an invitation URL.
|
||||
|
||||
1. Go again into the [Applications page](https://discord.com/developers/applications) and click on your bot.
|
||||
2. Go to the "OAuth2" tab and click on the subpage "URL Generator".
|
||||
\image html create_application_navigate_to_url_generator.png
|
||||
3. Select the `bot` scope. If your bot uses slash commands, also select `applications.commands`. You can read more about scopes and which you need for your application [here](https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes).
|
||||
4. Choose the permissions required for your bot to function in the "Bot Permissions" section.
|
||||
5. Copy and paste the resulting URL in your browser. Choose a server to invite the bot to, and click "Authorize".
|
||||
|
||||
\note For bots with elevated permissions, Discord enforces two-factor authentication on the bot owner's account when added to servers that have server-wide 2FA enabled.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- Stuck? You can find us on the [official discord server](https://discord.gg/dpp) - ask away! We don't bite!
|
||||
31
DPP-master/docpages/make_a_bot/windows_vs.md
Normal file
31
DPP-master/docpages/make_a_bot/windows_vs.md
Normal file
@@ -0,0 +1,31 @@
|
||||
\page build-a-discord-bot-windows-visual-studio Building a Discord Bot on Windows Using Visual Studio
|
||||
|
||||
To create a basic bot using **Visual Studio 2019** or **Visual Studio 2022**, follow the steps below to create a *working skeleton project you can build upon*.
|
||||
|
||||
If you prefer a video tutorial, you can watch the video below! Otherwise, scroll past and keep reading!
|
||||
|
||||
## Video Tutorial
|
||||
|
||||
\htmlonly
|
||||
|
||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/JGqaQ9nH5sk?si=dung8KuYbWvP2_oL" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||
|
||||
\endhtmlonly
|
||||
|
||||
## Text Tutorial
|
||||
|
||||
1. Make sure you have Visual Studio 2019 or 2022. Community, Professional or Enterprise work fine. These instructions are not for Visual Studio Code. You can [download the correct version here](https://visualstudio.microsoft.com/downloads/). Note that older versions of Visual Studio will not work as they do not support enough of the C++17 standard.
|
||||
2. Clone the [template project](https://github.com/brainboxdotcc/windows-bot-template/). Be sure to clone the entire project and not just copy and paste the `.cpp` file.
|
||||
3. Double click on the `MyBot.sln` file in the folder you just cloned:
|
||||
\image html vsproj_1.png
|
||||
4. Add your bot token (see \ref creating-a-bot-application) and guild ID to the example program:
|
||||
\image html vsproj_2.png
|
||||
5. Click "Local Windows debugger" to compile and run your bot!
|
||||
\image html vsproj_3.png
|
||||
6. Observe the build output. There may be warnings, but so long as the build output ends with "1 succeeded" then the process has worked. You may now run your bot!
|
||||
\image html vsproj_14.png
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- If you get an error that a DLL is missing (e.g. `dpp.dll` or `opus.dll`) when starting your bot, then simply copy all DLLs from the **bin** directory of where you cloned the D++ repository to, into the same directory where your bot's executable is. You only need to do this once. There should be several of these DLL files: `dpp.dll`, `zlib.dll`, `openssl.dll` and `libcrypto.dll` (or similarly named SSL related files), `libsodium.dll` and `opus.dll`. Note the template project does this for you, so you should never encounter this issue.
|
||||
- Stuck? You can find us on the [official Discord server](https://discord.gg/dpp) - ask away! We don't bite!
|
||||
19
DPP-master/docpages/make_a_bot/windows_wsl.md
Normal file
19
DPP-master/docpages/make_a_bot/windows_wsl.md
Normal file
@@ -0,0 +1,19 @@
|
||||
\page build-a-discord-bot-windows-wsl Building a Discord Bot on Windows Using WSL (Windows Subsystem for Linux)
|
||||
|
||||
This tutorial teaches you how to create a lightweight environment for D++ development using **WSL** and **Visual Studio Code**
|
||||
|
||||
\note **This Tutorial will use WSL's default distribution, Ubuntu**! You can use other distros if you wish, **but keep in mind the setup process might be different!** If you're aiming for production, we recommend you continue your path of becoming the master of all Discord bots \ref buildcmake "by visiting this page", otherwise keep following this guide!
|
||||
|
||||
1. Make sure you have installed your WSL 2 environment properly using [this guide to setup up WSL](https://docs.microsoft.com/en-us/windows/wsl/install) and [this guide to connect to Visual Studio Code](https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-vscode).
|
||||
2. Now open PowerShell as Administrator and type `wsl` to start up your subsystem. You may also type `ubuntu` into your search bar and open it that way.
|
||||
3. Head on over to your home directory using `cd ~`.
|
||||
4. Download the latest build for your distro using `wget [url here]`. In this guide we will use the latest build for 64 bit Ubuntu: `wget -O libdpp.deb https://dl.dpp.dev/latest`.
|
||||
5. Finally install all required dependencies and the library itself using `sudo apt-get install libopus0 libopus-dev libsodium-dev && sudo dpkg -i libdpp.deb && rm libdpp.deb`.
|
||||
6. Congratulations, you've successfully installed all dependencies! Now comes the real fun: Setting up the environment! For this tutorial we'll use a as small as possible setup, so you might create a more advanced one for production bots.
|
||||
7. Create a new directory, inside your home directory, using `mkdir MyBot`. Then, you want to open that directory using `cd MyBot`.
|
||||
8. Now that you've a directory to work in, type `touch mybot.cxx` to create a file you can work in!
|
||||
9. Now, head on over to Visual Studio Code. Press `CTRL+SHIFT+P` and type `Remote-WSL: New WSL Window` (You don't have to type all of it, it will auto-suggest it!). This will bring up a new window. In the new window, choose `open folder` and choose the directory you've created prior (It should be within your home directory). Press OK and now you have your Folder opened as a Workspace!
|
||||
10. Add code to your CXX file (We suggest using the \ref firstbot "first bot page" if this is your first time!) and compile it by running `g++ -std=c++17 *.cxx -o bot -ldpp` in the same folder as your cxx file. This will create a "bot" file!
|
||||
11. You can now start your bot by typing `./bot`!
|
||||
|
||||
If everything was done right, you should be able to see your bot working!
|
||||
21
DPP-master/docpages/make_a_bot/xcode.md
Normal file
21
DPP-master/docpages/make_a_bot/xcode.md
Normal file
@@ -0,0 +1,21 @@
|
||||
\page build-a-bot-xcode Building a Discord Bot using Xcode (OSX)
|
||||
|
||||
\warning This tutorial expects you to have installed D++ via homebrew. If you haven't, please visit \ref install-brew.
|
||||
|
||||
To create a bot with Xcode, follow the steps below to create a *working skeleton project you can build upon*.
|
||||
|
||||
\note Since the brew package for D++ only supports C++17, you can't use coro with this project. If you wish to use coro, you need to \ref buildosx "build from source". If you do build from source, look to replace the include and library paths in this project to `/usr/local/include` and `/usr/local/lib`.
|
||||
|
||||
1. Make sure you have Xcode downloaded, along with the developer command tools (for AppleClang).
|
||||
2. Clone the [template project](https://github.com/Jaskowicz1/mac-bot-template/). **Make sure you download the entire project and not just the .cpp file.**
|
||||
3. Open Xcode, hit "Open Existing Project" or "File"->"Open", navigate to the template folder and open the .xcodeproj file. You can also double click the file in Finder.
|
||||
4. Replace "add your token here" with your bot's token in the "main" file.
|
||||
\image html xcode_token.png
|
||||
5. Click the run button to compile and run your bot!
|
||||
\image html xcode_run.png
|
||||
6. Observe the output and watch your bot run! You may get warnings in this stage and that's okay!
|
||||
\image html xcode_output.png
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- Stuck? You can find us on the [official Discord server](https://discord.gg/dpp) - ask away! We don't bite!
|
||||
Reference in New Issue
Block a user