Giter Site home page Giter Site logo

alexflipnote / discord_bot.py Goto Github PK

View Code? Open in Web Editor NEW
559.0 30.0 190.0 259 KB

๐Ÿบ A simple discord bot that helps you getting started within discord.py

Home Page: https://discord.gg/AlexFlipnote

License: MIT License

Python 98.63% Dockerfile 0.45% Batchfile 0.92%
discord bot python simple commands starterkit compact small discord-bot easy

discord_bot.py's Introduction

discord_bot.py

Do you need more help? Visit my server here: https://discord.gg/AlexFlipnote ๐Ÿบ

Requirements

Useful to always have

Keep this saved somewhere, as this is the docs to discord.py@rewrite. All you need to know about the library is defined inside here, even code that I don't use in this example is here.

This code is also made to be as typing friendly as possible with comments and everything. I recommend having Visual Studio Code with the Python extension installed to help you out with the code.

How to setup

  1. Make a bot here and grab the token Image_Example1

  2. Rename the file .env.example to .env, then fill in the required spots, such as token, prefix and game

  3. To install what you need, do pip install -r requirements.txt
    (If that doesn't work, do python -m pip install -r requirements.txt)
    NOTE: Use pip install with Administrator/sudo

  4. Start the bot by having the cmd/terminal inside the bot folder and type python index.py

  5. You're done, enjoy your bot!

FAQ

Q: I don't see my bot on my server!
A: Invite it by using this URL: https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot
Remember to replace CLIENT_ID with your bot client ID

Q: There aren't that many commands here...
A: Yes, I will only provide a few commands to get you started, maybe adding more later.

Q: Why the beer with the discord logo?
A: Because the framework is made so simple that even a drunk guy can set it up.

Optional tools

Flake8

Flake8 is a tool that helps you keep your code clean. Most coding softwares will have a plugin that supports this Python module so it can be integrated with your IDE. To install it, simply do pip install flake8. If you're using python 3.7, install by doing pip install -e git+https://gitlab.com/pycqa/flake8#egg=flake8

PM2

PM2 is an alternative script provided by NodeJS, which will reboot your bot whenever it crashes and keep it up with a nice status. You can install it by doing npm install -g pm2 and you should be done. Keep in mind that this PM2 file is made to work on my own Linux instance, you might need to change the interpreter value.

# Start the bot
pm2 start pm2.json

# Tips on common commands
pm2 <command> [name]
  start discord_bot.py    Run the bot again if it's offline
  list                    Get a full list of all available services
  stop discord_bot.py     Stop the bot
  reboot discord_bot.py   Reboot the bot

Docker

Docker is an alternative to run the bot 24/7 and always reboot again whenever it crashed. You can find the install manual here. You don't have to get it, but if you're used to having Docker, it's available at least.

# Build and run the Dockerfile
docker-compose up -d --build

# Tips on common commands
docker-compose <command>
  ps      Check if bot is online or not (list)
  down    Shut down the bot
  reboot  Reboot the bot without shutting it down or rebuilding
  logs    Check the logs made by the bot.

discord_bot.py's People

Contributors

alexflipnote avatar atiwiex avatar bobby-burns avatar clovismint avatar cyyynthia avatar grantwforsythe avatar halidin avatar harshal6927 avatar k1m0ch1 avatar lepeli avatar maimisu avatar marck avatar mesiik avatar nirlep5252 avatar perryprog avatar piemadd avatar sirromey avatar soheab avatar thunderstorm010 avatar voiding avatar yabberish avatar zenrac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord_bot.py's Issues

Error

Can somebody help, when i typed python3 index.pyit showed me this error:

[SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')]

discord.ext.commands.errors.CommandNotFound

image

only the help command is working and it gives this `โ€‹No Category: help Shows this message

Type shelp command for more info on a command.
You can also type shelp category for more info on a category.
`

[QUESTION]Whats up with the api tokens?

Whats the point with having api tokens if you provide no documentation for them? And isnt this repo supposed to be for new coming users to dpy? i dont think having to find your api docs to use your dog / cat / etc commands is nice to have for new people.

Music Related command not working

The command playing gets this error.
image
Unfortunately, this is all I could trace.
The code doesn't seem to have problems as far as I can tell. Will continue to investigate.

how to make bot not case sensitive?

for most discord bots you can add case_insensitive=true and the bot won't be case sensitive, but because of how the bot is setup using the config.json file you can't

from discord.utils import default not working

Whenever i try hosting my bot with a few code of this source code i get this error
well i rename utils to discord.utils thought it would work but didnt
if you could add me on discord and we discuss about it @sashank#7581 or join my test server for a while https://discord.gg/s8S8a3d

**PS C:\Users\Sasha\Desktop\Toxy Bot> & C:/Users/Sasha/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/Sasha/Desktop/Toxy Bot/Toxy.py"
cogs.Information can not be loaded:
Traceback (most recent call last):
File "C:\Users\Sasha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 596, in _load_from_module_spec
spec.loader.exec_module(lib)
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "c:\Users\Sasha\Desktop\Toxy Bot\cogs\Information.py", line 9, in
from discord.utils import default
ImportError: cannot import name 'default' from 'discord.utils' (C:\Users\Sasha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\utils.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "c:/Users/Sasha/Desktop/Toxy Bot/Toxy.py", line 83, in
raise e
File "c:/Users/Sasha/Desktop/Toxy Bot/Toxy.py", line 80, in
client.load_extension(cog)
File "C:\Users\Sasha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 653, in load_extension
self._load_from_module_spec(spec, name)
File "C:\Users\Sasha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 599, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.Information' raised an error: ImportError: cannot import name 'default' from 'discord.utils' (C:\Users\Sasha\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\utils.py)**

Api Version

AttributeError: module 'discord.http' has no attribute 'API_VERSION'

unclosed aiohttp clientSession

Im using your aiohttp code, and every time i close my bot it tells me that close() needs to be await it, but when i make it an async function it just doesnt get ran, how do i fix it or could you?

= { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };

= {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};

The bot does not start

Hello, I'm trying to run the bot, I'm doing whatever it takes. Bot starts but does not respond to commands. There are no errors in the console. When I stop the CTRL + C script, I have something like this

Task exception was never retrieved
future: <Task finished name='Task-9' coro=<AutoShardedConnectionState._delay_ready() done, defined at C:\Users\erwin\anaconda3\lib\site-packages\discord\state.py:1079> exception=AttributeError("'AutoShardedConnectionState' object has no attribute 'shard_id'")>
Traceback (most recent call last):
  File "C:\Users\erwin\anaconda3\lib\site-packages\discord\state.py", line 1118, in _delay_ready
    await utils.sane_wait_for(futures, timeout=timeout)
  File "C:\Users\erwin\anaconda3\lib\site-packages\discord\utils.py", line 352, in sane_wait_for
    raise asyncio.TimeoutError()
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\erwin\anaconda3\lib\site-packages\discord\state.py", line 1120, in _delay_ready
    log.warning('Shard ID %s failed to wait for chunks (timeout=%.2f) for %d guilds', self.shard_id,
AttributeError: 'AutoShardedConnectionState' object has no attribute 'shard_id'```

Bug after installation

Hi !

I have follow the tutorial, and when i lauch the py :

File "index.py", line 25
    bot.load_extension(f"cogs.{name}")
                                    ^
SyntaxError: invalid syntax

Thx

have some issues get help out the bot

Traceback (most recent call last): File "C:\Users\ow that is the other\Desktop\discordbotpy\index.py", line 51, in <module> bot.run(config.token) File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\client.py", line 598, in run return future.result() File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\client.py", line 579, in runner await self.start(*args, **kwargs) File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\client.py", line 543, in start await self.connect(reconnect=reconnect) File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\client.py", line 457, in connect await self._connect() File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\shard.py", line 274, in _connect f.result() File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\shard.py", line 78, in poll await self.ws.poll_event() File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\gateway.py", line 469, in poll_event await self.received_message(msg) File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\gateway.py", line 423, in received_message func(data) File "C:\Users\ow that is the other\AppData\Roaming\Python\Python38\site-packages\discord\state.py", line 409, in parse_message_reaction_add emoji = PartialEmoji.with_state(self, animated=emoji_data['animated'], id=emoji_id, name=emoji_data['name']) KeyError: 'animated' Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000020EDB233550> Traceback (most recent call last): File "C:\Python38\lib\asyncio\proactor_events.py", line 116, in __del__ self.close() File "C:\Python38\lib\asyncio\proactor_events.py", line 108, in close self._loop.call_soon(self._call_connection_lost, None) File "C:\Python38\lib\asyncio\base_events.py", line 711, in call_soon self._check_closed() File "C:\Python38\lib\asyncio\base_events.py", line 504, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed C:\Users\ow that is the other\Desktop\discordbotpy\utils\http.py:24: RuntimeWarning: coroutine 'ClientSession.close' was never awaited

When I type out help with the command reboot my bot when getting me these issues

components/stream/worker.py (ERROR)

HI,
I get thousands of errors in the log:
Error parsing AU headers
11:08:11 โ€“ components/stream/worker.py (ERROR) - il messaggio si รจ verificato per la prima volta alle 10:08:45 e compare 6388 volte
Error parsing AU headers (repeated 12 more times)
11:08:11 โ€“ components/stream/worker.py (ERROR) - il messaggio si รจ verificato per la prima volta alle 10:08:44 e compare 4300 volte

This causes the log fill up for several gb until homeassistant freeze in 2/3 days.

bot is not coming online

hi i did everything listed but the bot isn't coming online I did this on repl.it please respond soon

source

Source command has the same description as invite.

No module name discord

no module name discord, but when I delete the import discord, the index.js syntax occurs?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.