我如何/什么是从 python 中的 Discord 角色中删除所有用户的最佳方法?

How do I / what is the best way to remove all users from a Discord Role in python?

总计 我是一个总计 discord/python 菜鸟,我真的没有任何代码可以展示,因为我什至不知道从哪里开始。我想要做的就是将所有人从某个不和谐的角色中移除。

假设角色是 "Warrior" 并且其中有 5 个人,我不想完全删除角色,而是只想从中删除所有 5 个人。我想理论上我可以删除整个角色然后重新创建它,让我知道你的想法和最好的方法。

这是相当冗长的回复,但我建议阅读整篇文章。

StackExchange 是一个人们 post 讨论代码的社区。恕我直言,我可以向您保证,如果我们看不到您尝试过的内容或任何现有代码,那么这里没有人(包括我)会为您编写代码。

如果你有相关的产品,人们可以查看并找出错误,那么你在这个网站上的运气肯定会更好and/or帮助你在它的基础上继续发展。

同时,在此处查看非官方用户 Discord API 服务器:https://discordapp.com/invite/discord-API

当我处在你的位置时,这个 discord 服务器在回答有关 Discord API 的任何问题时非常有帮助,因为那里 99.9% 的人确切地知道你的问题是什么以及如何解决它。在您构建代码时,人们总是在线回答您的问题。

如果您在启动代码方面需要帮助,基本步骤如下:

  1. pip 安装 discord API
  2. https://discordapp.com/developers/docs/intro
  3. 上创建一个机器人用户
  4. 使用机器人令牌编写您的代码

因为我不知道到目前为止你的机器人到底取得了什么进展,所以我只是在 python 中串了一些线框代码来开始。

import discord
import asyncio
from discord.ext import commands
description = "desc"
bot = commands.Bot(command_prefix='?', description=description)
#startup command
@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')
#category of main commands
class Main_Commands():
    def __init__(self, bot):
        self.bot = bot
#ping command test
@bot.command(pass_context=True)
async def ping(ctx):
    await bot.say("pong")
#when the user types in ?ping, the bot will return "pong"
#This is an example of a simple command in this language
#RunBot
bot.run("TOKEN GOES HERE")
# (C) 2017
# All rights reserved
# Any part of this program may be used and/or modified at the users discretion

无论如何,我希望这个回复对你有所帮助。如果您需要我的任何帮助,请随时通过 Discord 上的 ABoostED#6865 给我发消息,只要我的日程安排允许,我会尽量回来。

编码愉快!!

P.S。查看 API 参考 http://discordpy.readthedocs.io/en/latest/index.html