python - 通过用户提及向用户添加角色
问题描述
我试图制作一个能够通过用户提及向用户添加角色的机器人。我也想在命令中传递角色。所以语法应该是:
!addrole ROLENAME @user
我试过这个:
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord.utils import get
def read_token():
with open("token.txt", "r") as f:
lines = f.readlines()
return lines[0].strip()
token = read_token()
bot = commands.Bot(command_prefix='!')
@bot.command(pass_context=True)
async def addrole(ctx, arg1, member: discord.Member):
role = get(member.guild.roles, name={arg1})
await member.add_roles(role)
bot.run(token)
但它不起作用。我收到错误:
AttributeError: 'NoneType' object has no attribute 'id'
解决方案
推荐阅读
- laravel - 语法错误,意外的“布局”(T_STRING),期待“)”(查看:C:\xampp7\htdocs\shopping\resources\views\auth\register.blade.php)
- php - php - 如何计算比例不同于 0-100 的百分比?
- php - Magento 2 注册并登录 REST API
- javascript - 我想使用 react js 根据所选国家/地区组合框选项使其他组合框可见
- javascript - 数组副本的变异也会改变原始数组!为什么?
- haskell - How can I generate a random sequence of elements from a list in Haskell?
- r - 无法将其他参数传递给 group_map
- git - 在 .gitignore 中添加不需要的文件后,我仍然会在 Github 上上传它们
- python - Nonetype 错误未通过 if-else 条件文本抓取 BeautifulSoup 修复
- angular - 如何加速 Angular 启动?