Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
- Pick a username
- Email Address
- Password
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
So, first you need to go here here and create an application (it will need you to log in). Click on «New Application». You’ll see a couple of things.
App name is the username of your bot. Description is kinda irrelevant, and so is Redirect URIs, so you can leave them blank. Same goes for the «App Icon» (which is the profile picture of your bot), but I suggest putting something there. So technically all you need to do is fill out the App name. After filling in the blanks, create your app.
Now, you’ll see something called «Client/Application ID: [numbers]», and «Token: <click to reveal>. Reveal your «Token», and write it down somewhere. Then copy your Client/Application ID and paste it to this link’s <client id> (delete the brackets also):
https://discordapp.com/oauth2/authorize?client_id=<CLIENT_ID>&scope=bot
so it looks something like
https://discordapp.com/oauth2/authorize?client_id=123123123123123&scope=bot
Now enter that URL to your browsers URL bar.
It might ask for a log in. If so, log in. Then, chose the server you want your bot to be on.
Now you’re almost done. Now go to your bot’s files. Depending on your bot, there should be a config file where you can enter your «bot token». On Music Bot (aka Rhino Bot), you’ll find this on config>options.ini. On Red Bot, the bot will ask for a token when you run it for the first time. When you find where you’re supposed to enter your token, simply paste the token which you wrote down somewhere earlier.
And now you’re done.
I’m trying to make a discord bot (with the bot tag) that can join other servers.
I will be able to do this, if I can set up a redirect URI for it. I already have the bot account set up, and it already functions with it (except for joining servers).
I was wondering how to set up a redirect URI for discord OAuth2?
nortex_dev
1511 gold badge2 silver badges7 bronze badges
asked Jun 4, 2016 at 1:45
1
To add your bot to a server you need to make a redirect url with your Client ID
Just replace the Client Id with your Client Id:
https://discordapp.com/oauth2/authorize?&client_id=[CLIENTID]&scope=bot
That’s all! Now you just need to click on it!
answered Oct 8, 2016 at 19:00
MondanzoMondanzo
691 silver badge3 bronze badges
1
You need to have your own webserver with some path to make your redirect url. For example, if you owned example.com, you could have example.com/discord be the url to redirect the client to after they login via Discord.
answered Jun 18, 2016 at 4:30
NathanNathan
2,6315 gold badges28 silver badges43 bronze badges
I’m assuming you are trying to use the guilds.join scope and it tells you to give a redirect URI. I think you are mistaking the guilds.join for the bot because it is actually the scope for letting your application join servers for the client (you can see this by going on the link https://discordapp.com/oauth2/authorize?&client_id=[CLIENTID]&scope=guilds.join
and replace [CLIENTID]
with the application client ID).
This means the link with the scope guilds.join will be on a website that you own and once the user either grants and denies this, the grant page will redirect the client back to the website.
Also, your bot cannot actually self-join servers simply because of how it was made. Bots must be manually authorized through OAuth. If you want a bot to join the server itself, it could use the invite link to get the server and DM the server owner (that can be found using the property) a OAuth link for the bot. Since the bot is not in the server it wants to join, you will need to do this method through the rest client. If you don’t mind doing it like other bots, you can get the bot to provide the join link like other bots with a command like !invite
.
Edit: If you want more information about using guilds.join, the documentation link is here: https://discordapp.com/developers/docs/resources/guild#add-guild-member
answered Feb 2, 2020 at 16:56
Ситуация:
Я пытаюсь создать простого бота Discord с pycord, но каждый раз, когда я запускаю код, он выдает эту ошибку:
Traceback (most recent call last):
File "main.py", line 3, in <module>
bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'
Код:
import discord
bot = discord.Bot()
@bot.slash_command()
async def test(ctx):
await ctx.send('Success!')
bot.run('token')
Что я сделал:
Я уже проверил, установлен ли у меня pycord и верен ли мой токен.
3 ответа
Лучший ответ
PyCord 2 beta 1 только что был выпущен, поэтому теперь вы можете установить его с помощью
pip install py-cord==2.0.0b1
А не устанавливать версию из исходников.
Однако, чтобы пример заработал, вам нужно добавить область applications.commands
к URL-адресу OAuth2 и повторно зарегистрировать бота на тестовом сервере.
Кроме того, краткое руководство теперь предлагает добавить список идентификаторов гильдий (серверов). при создании slash_command
:
Атрибут
guild_ids
содержит список гильдий, в которых эта команда будет активен. Если вы его опустите, команда будет глобально доступны, и регистрация может занять до часа.
4
Mark Booth
30 Янв 2022 в 05:21
При просмотре вашего сообщения об ошибке:
Traceback (most recent call last):
File "main.py", line 3, in <module>
bot = discord.Bot()
AttributeError: module 'discord' has no attribute 'Bot'
Важно заметить, что AttributeError сообщает вам, что модуль, который вы импортировали, не имеет атрибута Bot ().
Это указывает на то, что вы его неправильно используете.
Ознакомьтесь с документацией для правильного использования, а также на этот руководство
Вы увидите, что вам нужно использовать.
# bot.py
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
client.run(TOKEN)
Редактировать после комментария @Taku
После комментария ниже я считаю, что может потребоваться обновление библиотеки, как это сделано в примере
Помимо требования префикса команды, как это сделано в примере в URL-адресе
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=">")
@bot.command()
async def ping(ctx):
await ctx.send("pong")
bot.run("token")
2
Kwsswart
26 Окт 2021 в 17:39
Причина этой ошибки в том, что ваша версия pycord — v1.7.3, которая не поддерживает используемый вами синтаксис. Вам необходимо выполнить обновление до версии 2.0.0 с помощью этих команд (Windows):
git clone https://github.com/Pycord-Development/pycord
cd pycord
pip install -U .
Или pip install -U .[voice]
, если вам требуется голосовая поддержка
2
Hridesh MG
28 Янв 2022 в 10:47
Go to discordapp
r/discordapp
Imagine a Place… where you can belong to a school club, a gaming group, or a worldwide art community. Where just you and handful of friends can spend time together. A place that makes it easy to talk every day and hang out more often.
Members
Online
•
How the fuck do I make a bot join a server?
All of the stuff with OAuth is going over my head, can someone explain it to me? I just want to have a my bot, which currently does nothing, join a server. What do I have to do to make that happen?
Archived post. New comments cannot be posted and votes cannot be cast.
Example: how to disable a discord bots OAuth2 code
import base64
API_ENDPOINT = 'https://discord.com/api/v6'
CLIENT_ID = '332269999912132097'
CLIENT_SECRET = '937it3ow87i4ery69876wqire'
def get_token():
data = {
'grant_type': 'client_credentials',
'scope': 'identify connections'
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
r = requests.post('%s/oauth2/token' % API_ENDPOINT, data=data, headers=headers, auth=(CLIENT_ID, CLIENT_SECRET))
r.raise_for_status()
return r.json()
Tags:
Misc Example
Related
I’m trying to make a discord bot (with the bot tag) that can join other servers.
I will be able to do this, if I can set up a redirect URI for it. I already have the bot account set up, and it already functions with it (except for joining servers).
I was wondering how to set up a redirect URI for discord OAuth2?
nortex_dev
1711 gold badge2 silver badges7 bronze badges
asked Jun 4, 2016 at 1:45
1
To add your bot to a server you need to make a redirect url with your Client ID
Just replace the Client Id with your Client Id:
https://discordapp.com/oauth2/authorize?&client_id=[CLIENTID]&scope=bot
That’s all! Now you just need to click on it!
answered Oct 8, 2016 at 19:00
MondanzoMondanzo
691 silver badge4 bronze badges
1
You need to have your own webserver with some path to make your redirect url. For example, if you owned example.com, you could have example.com/discord be the url to redirect the client to after they login via Discord.
answered Jun 18, 2016 at 4:30
NathanNathan
2,6595 gold badges29 silver badges44 bronze badges
I’m assuming you are trying to use the guilds.join scope and it tells you to give a redirect URI. I think you are mistaking the guilds.join for the bot because it is actually the scope for letting your application join servers for the client (you can see this by going on the link https://discordapp.com/oauth2/authorize?&client_id=[CLIENTID]&scope=guilds.join
and replace [CLIENTID]
with the application client ID).
This means the link with the scope guilds.join will be on a website that you own and once the user either grants and denies this, the grant page will redirect the client back to the website.
Also, your bot cannot actually self-join servers simply because of how it was made. Bots must be manually authorized through OAuth. If you want a bot to join the server itself, it could use the invite link to get the server and DM the server owner (that can be found using the property) a OAuth link for the bot. Since the bot is not in the server it wants to join, you will need to do this method through the rest client. If you don’t mind doing it like other bots, you can get the bot to provide the join link like other bots with a command like !invite
.
Edit: If you want more information about using guilds.join, the documentation link is here: https://discordapp.com/developers/docs/resources/guild#add-guild-member
answered Feb 2, 2020 at 16:56