# discord bot 指令設計 ## 基本架構 ```python= @bot.tree.command(name='example_code') async def example_code(interaction: discord.Interaction): #回覆的程式 ``` ## 發送訊息 ```python= @bot.tree.command(name='example_code') async def example_code(interaction: discord.Interaction): await interaction.response.send_message("要發送的訊息") ``` ## 有參數的指令 ```python= @bot.tree.command(name='example_code') @app_commands.describe(say="say hello") async def example_code(interaction: discord.Interaction, say:str): await interaction.response.send_message(say) ``` ## f字串 ```python= name = "aaa" pt = 50 print(f"名字是 {name}, pt有{pt}") > 名字是 aaa, pt有50 ``` ## embed 使用embed生成器後複製貼上到code裡 https://cog-creators.github.io/discord-embed-sandbox/ ```python= embed=discord.Embed(title="標題", description="敘述", color=0xff0000) embed.add_field(name="name", value="value", inline=False) embed.add_field(name="name", value="value", inline=True) embed.add_field(name="name", value="value", inline=True) await ctx.send(embed=embed) ``` ## for 迴圈 ```python= for i in range(1,5): print(i) > 1 > 2 > 3 > 4 ``` ```python= for gulid in bot.guilds: for channel in guild.channels: await channel.send("hi") > 在機器人的每個伺服器裡的每個頻道傳送hi ``` ## google 直接到 google 搜尋你的問題 https://www.google.com/ ## discord API 查詢API方式: https://hackmd.io/@QBe3gR3hR1qK4S8Za3XfLA/r1TLp7Csj 到 discord API 搜尋你的問題(不過這比較難,需要有一些基礎) https://discordpy.readthedocs.io/en/stable/api.html ## stack overflow 在 stack overflow 搜尋你的問題(不過通常在 google 找也會跳 stack overflow 的網站) https://stackoverflow.com/
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.