【问题标题】:Discord Python Change regionDiscord Python 更改区域
【发布时间】:2019-04-15 17:35:31
【问题描述】:

对不起,如果这是一个如此愚蠢的问题,但我想知道这个命令有什么问题,因为我收到 discord.ext.commands.errors.BadArgument: Converting to "EnumMeta" failed. 作为错误。错误究竟是什么意思,正确的命令是什么?

@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')

【问题讨论】:

    标签: python-3.x discord discord.py


    【解决方案1】:

    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 raised an exception: AttributeError: 'ServerRegion' object has no attribute 'icon' 出现了,但是:(
    • @DanielCasares 尝试将您的edit_server 行更改为await self.bot.edit_server(ctx.message.server, region=region)。您还应该在if 中添加return,因此如果未设置region,则不要尝试编辑服务器。
    • discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'discord.server' has no attribute 'region'我做错了吗?
    • @DanielCasares 它对我有用。该错误在哪一行?
    • await self.bot.say("Ok! We're now in " + server.region + " :smiley:") AttributeError: module 'discord.server' has no attribute 'region' 这给出了错误,但您的代码工作正常,非常感谢!因为这个我已经疯了
    猜你喜欢
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2020-07-28
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多