Discord.py ctx.guild.edit works but not self.bot.guild.edit?

一笑奈何 提交于 2021-02-05 11:18:33

问题


Like the title says, I'm trying to do guild edits but on an events. Here's part of my code:

    @commands.guild_only()
    async def on_ready(self):
    server = self.bot.get_guild("serverid")
        while True:
            await self.bot.guild.edit(guild=server, name="foo")
            await asyncio.sleep(1)
            await self.bot.guild.edit(guild=server, name="bar")
            await asyncio.sleep(1)

I've already tested it with a standalone command, so I know that ctx.guild.edit works but I'm not sure how to get it to work in an event.


回答1:


You should call edit directly from the Guild object server

async def on_ready(self):
server = self.bot.get_guild(SERVER_ID)
while server is not None:
    await server.edit(name="foo")
    await asyncio.sleep(1)
    await server.edit(name="bar")
    await asyncio.sleep(1)

Also, make sure that you're passing the id of the guild as an int and not a string, and the guild_only decorator should only be used on commands.



来源:https://stackoverflow.com/questions/59365696/discord-py-ctx-guild-edit-works-but-not-self-bot-guild-edit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!