Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 不协调变化区_Python 3.x_Discord_Discord.py - Fatal编程技术网

Python 3.x 不协调变化区

Python 3.x 不协调变化区,python-3.x,discord,discord.py,Python 3.x,Discord,Discord.py,很抱歉,如果这是一个如此愚蠢的问题,我想知道这个命令有什么问题,因为我得到了discord.ext.commands.errors.BadArgument:转换为“EnumMeta”失败。是一个错误。错误的确切含义是什么?正确的命令是什么 @commands.command(pass_context = True) @commands.has_permissions(manage_server=True) async def region(self, ctx, region=discord.Se

很抱歉,如果这是一个如此愚蠢的问题,我想知道这个命令有什么问题,因为我得到了
discord.ext.commands.errors.BadArgument:转换为“EnumMeta”失败。
是一个错误。错误的确切含义是什么?正确的命令是什么

@commands.command(pass_context = True)
@commands.has_permissions(manage_server=True)
async def region(self, ctx, region=discord.ServerRegion):
    """Changes the server region."""
    if not region:
        await self.bot.say("What region are we changing to, {ctx.message.author.mention}?")
    await self.bot.edit_server(region)
    await self.bot.say("Ok! We're now in " + str(ctx.message.server.region) + " :smiley:")
    print('ok')

ServerRegion
没有内置转换器。幸运的是,通过使用
ServerRegion('amsterdam')
相当于
ServerRegion这一事实,我们可以很容易地完成这项工作。amsterdam

region_converter = lambda region: discord.ServerRegion('-'.join(region.lower().split()))

@commands.command(pass_context = True)
@commands.has_permissions(manage_server=True)
async def region(self, ctx, *, region: region_converter=None):
    """Changes the server region."""
    if not region:
        await self.bot.say("What region are we changing to, {ctx.message.author.mention}?")
        return
    await self.bot.edit_server(ctx.message.server, region=region)
    await self.bot.say("Ok! We're now in " + str(ctx.message.server.region) + " :smiley:")
    print('ok')

谢谢你的回答
discord.ext.commands.errors.CommandInvokeError:Command引发异常:AttributeError:“ServerRegion”对象没有属性“icon”
显示,但是:(@DanielCasares尝试将
edit_server
行更改为
wait self.bot.edit_服务器(ctx.message.server,region=region)
。您还应该在
if
中添加一个
return
,这样,如果未设置
区域
,您就不会尝试编辑服务器。
discord.ext.commands.errors.CommandInvokeError:Command引发异常:AttributeError:module'discord.server'没有属性'region'
我做错了什么吗?@DanielCasares It's w为我工作。错误在哪一行?
等待self.bot。说(“好的!我们现在在”+server.region+”:smiley:“)AttributeError:module'discord.server'没有属性'region'
这是一个错误,但是你的代码工作得很好,非常感谢!我已经为此发疯了