[英]Discord.py get names of all guilds bot is in into an 1 embed/message
我想將 totalguilds 命令變成 1 個消息而不是其中的許多。 我怎么做?
@bot.command()
async def showguilds(ctx):
for guild in bot.guilds:
await ctx.send(guild.name)
這可以通過瀏覽bot.guilds
並將其添加到變量來完成。
@bot.command()
async def showguilds(ctx):
message = ""
for guild in bot.guilds:
message += f"{guild.name}\n"
await ctx.send(message)
或者,您可以使用列表:
@bot.command()
async def showguilds(ctx):
messages = []
for guild in bot.guilds:
messages.append(f"{guild.name}")
await ctx.send("\n".join(messages))
如果您希望 1 行中的 1 條消息中的所有公會,那么 Łukasz Kwieciński 的解決方案:
@bot.command()
async def showguilds(ctx):
await ctx.send("\n".join(bot.guilds))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.