如何加入服务器? [英] How to join a server?

查看:118
本文介绍了如何加入服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python设置Discord机器人。我有一个想让该机器人加入的先前存在的不和谐服务器,但是这样做很困难。

I'm trying to setup a discord bot with python. I have a pre-existing discord server that I would like the bot to join, but I'm having a hard time doing so.

import discord
import asyncio
import logging

logging.basicConfig(level=logging.INFO)

client = discord.Client()

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')
    print(client)


@client.event
async def on_message(message):
    print(message)
    if message.content.startswith('!test'):
        counter = 0
        tmp = await client.send_message(message.channel, 'Calculating messages...')
        async for log in client.logs_from(message.channel, limit=100):
            if log.author == message.author:
                counter += 1

        await client.edit_message(tmp, 'You have {} messages.'.format(counter))
    elif message.content.startswith('!sleep'):
        await asyncio.sleep(5)
        await client.send_message(message.channel, 'Done sleeping')

client.run('token')

这实际上是GitHub页面上提供的基本discord.py脚本。但是,我似乎无法弄清楚如何使其真正加入我的服务器。当将此行插入 on_ready 函数时:

This is essentially the basic discord.py script as given on the GitHub page. However, I can't seem to figure out how to have it actually join my server. When inserting this line into the on_ready function:

server = await client.accept_invite('instant-invite-code')

替换为 instant-invite-code我实际的即时邀请代码(我尝试了discord.gg/代码和代码),都得到

with "instant-invite-code" replaced with my actual instant invite code (I tried both discord.gg/code and code), I get

discord.errors.Forbidden: FORBIDDEN (status code: 403): Bots cannot use this endpoint

日志记录确实有效;我得到带有用户名和ID的输出。我的机器人已使用Discord API注册,并且我已经有一个令牌。

Logging does actually work; I get output with my username and id. My bot is registered with the discord API and I already have a token.

推荐答案

我也遇到了一些麻烦。您需要做的是:

I had some trouble with this as well. What you need to do is:


  1. 转到不一致的开发者页面(如果尚未登录,请登录)。

  2. 使用您要添加到频道中的漫游器转到应用程序。

  3. 复制客户端/应用程序ID。

  4. 转到 https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID_GOES_HERE&scope=bot&permissions=0 <您可以在此处设置机器人的权限。 可以在此处计算权限

  5. 选择服务器并单击授权。

  1. Go to the Discord developer pages (login if you haven't).
  2. Go to the application with the bot you want to add to your channel.
  3. Copy the Client/Application ID.
  4. Go to https://discordapp.com/oauth2/authorize?client_id=CLIENT_ID_GOES_HERE&scope=bot&permissions=0 < You can set permissions for the bot here. Permissions can be calculated here.
  5. Select server and click authorize.

您的机器人现在将成为服务器的成员,并将响应您提供的命令。例如在给定的代码中进行测试。

Your bot will now be a member of the server and will respond to commands you give it. Ex. !test in the code you have given.

编辑:您现在可以使用权限链接( 1 )生成所需的整个URL。

You can now use the permissions link (1) to generate the entire URL needed.

这篇关于如何加入服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆