如何向 discord.py 命令添加参数?
How do I add arguments to a discord.py command?
我的代码是:
weather = Weather(unit=Unit.CELSIUS)
location = weather.lookup_by_location('toronto')
forecasts = location.forecast
embed = (discord.Embed(title="-=-__THE WEATHER__-=-", color=0x15dbc7))
embed.add_field(name="Clouds", value=forecasts[0].text, inline=False)
embed.add_field(name="Date", value=forecasts[0].date, inline=False)
embed.add_field(name="High", value=forecasts[0].high, inline=False)
embed.add_field(name="Low", value=forecasts[0].low, inline=False)
await bot.say(embed=embed)
如何让它用命令后的变量替换 0?
我拥有的标识命令的代码是
@bot.command(pass_context=True)
async def weather(ctx)
我使用的导入是:
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import random
import weather
from weather import Weather, Unit
您将在函数定义中传递该参数,以及让 discord.py
知道您希望将该值转换为哪种类型的 converter。
@bot.command(pass_context=True)
async def weather(ctx, index: int):
weather = Weather(unit=Unit.CELSIUS)
location = weather.lookup_by_location('toronto')
forecasts = location.forecast
embed = (discord.Embed(title="-=-__THE WEATHER__-=-", color=0x15dbc7))
embed.add_field(name="Clouds", value=forecasts[index].text, inline=False)
embed.add_field(name="Date", value=forecasts[index].date, inline=False)
embed.add_field(name="High", value=forecasts[index].high, inline=False)
embed.add_field(name="Low", value=forecasts[index].low, inline=False)
await bot.say(embed=embed)
您可以使用 !weather 3
从 Discord 调用它
我的代码是:
weather = Weather(unit=Unit.CELSIUS)
location = weather.lookup_by_location('toronto')
forecasts = location.forecast
embed = (discord.Embed(title="-=-__THE WEATHER__-=-", color=0x15dbc7))
embed.add_field(name="Clouds", value=forecasts[0].text, inline=False)
embed.add_field(name="Date", value=forecasts[0].date, inline=False)
embed.add_field(name="High", value=forecasts[0].high, inline=False)
embed.add_field(name="Low", value=forecasts[0].low, inline=False)
await bot.say(embed=embed)
如何让它用命令后的变量替换 0? 我拥有的标识命令的代码是
@bot.command(pass_context=True)
async def weather(ctx)
我使用的导入是:
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import random
import weather
from weather import Weather, Unit
您将在函数定义中传递该参数,以及让 discord.py
知道您希望将该值转换为哪种类型的 converter。
@bot.command(pass_context=True)
async def weather(ctx, index: int):
weather = Weather(unit=Unit.CELSIUS)
location = weather.lookup_by_location('toronto')
forecasts = location.forecast
embed = (discord.Embed(title="-=-__THE WEATHER__-=-", color=0x15dbc7))
embed.add_field(name="Clouds", value=forecasts[index].text, inline=False)
embed.add_field(name="Date", value=forecasts[index].date, inline=False)
embed.add_field(name="High", value=forecasts[index].high, inline=False)
embed.add_field(name="Low", value=forecasts[index].low, inline=False)
await bot.say(embed=embed)
您可以使用 !weather 3