Object 如何操作不协调对象?
我想获得使用该命令的用户的角色名,以便能够从用户中删除该命令,但我得到了这个响应Object 如何操作不协调对象?,object,python-3.6,discord,Object,Python 3.6,Discord,我想获得使用该命令的用户的角色名,以便能够从用户中删除该命令,但我得到了这个响应 import discord import discord.ext from discord.ext import commands from discord.ext.commands import Bot import asyncio bot=commands.Bot(command_prefix='v.') @bot.event async def on_ready(): print(bot.us
import discord
import discord.ext
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
bot=commands.Bot(command_prefix='v.')
@bot.event
async def on_ready():
print(bot.user.name)
@bot.command(pass_context=True)
async def role(ctx):
user_role=ctx.message.author.roles
print(user_role)
bot.run('bot token')
如何操作discord对象?您可以看到discord.Role对象的所有属性。所以你可以
[<discord.role.Role object at 0x067A83B0>, <discord.role.Role object at 0x067A8530>, <discord.role.Role object at 0x067A84B0>, <discord.role.Role object at 0x067A8630>]
我以下拉顺序获得名称成员Pink@Everyone如何使变量仅代表其中一个?用户角色是一个列表。。。如果您想要第一个,您可以使用用户角色[0]。名称。。。第二,您将执行用户角色[1]。名称等等
@bot.command(pass_context=True)
async def role(ctx):
user_role=ctx.message.author.roles
for r in user_role:
print(r.name)