问题
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