【发布时间】:2020-11-28 01:27:44
【问题描述】:
我正在编写一个机器人来在我的不和谐服务器上查找具有“管理员”角色的用户并打印信息(admin用户名)并将所有角色存储在一个列表中peopleWithRole:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="$")
role_name = "Admin"
peopleWithRole = []
@bot.event
async def on_ready():
print("Logged in as")
print(bot.user.name)
print("------")
role = discord.utils.find(
lambda r: r.name == role_name, guild.roles)
for user in guild.members:
if role in user.roles:
peopleWithRole.append(user)
bot.run("My token")
但是,当我运行它时,返回 error 'guild' 未定义。我刚开始使用 discord python 模块。在这种情况下我应该如何使用客户端或bot?。
【问题讨论】:
标签: python python-3.x discord