【发布时间】:2021-10-04 05:13:11
【问题描述】:
修复:添加 DiscordComponents(bot)
我正在尝试获取允许用户进行选择的按钮或下拉菜单。但是,我无法让它工作,因为这两种方法最终都会给我一个组件问题。
错误信息是: 第 134 行,以 rps 为单位 m = 等待 ctx.send( TypeError: send() 得到了一个意外的关键字参数“组件”
我已经 pip 安装了 discord_components 并导入了它。我对错误消息的来源感到困惑。
@bot.command(name = "rps")
async def rps(ctx):
ch1 = ["Rock","Scissors","Paper"]
comp = random.choice(ch1)
yet = discord.Embed(title = f"{ctx.author.display_name}'s RPS game", description = "You have yet to select anything")
win = discord.Embed(title = f"{ctx.author.display_name} Won!", descrption = "Congrats! You won.")
out = discord.Embed(title = f"{ctx.author.display_name} was too slow.", descrption = "Okay then you were just too slow for me. ")
lost = discord.Embed(title = f"{ctx.author.display_name} lost", descrption = "Aw darn. Unfortunatly you lost this one.")
tie = discord.Embed(title = f"{ctx.author.display_name} tied with the bot!", descrption = "Well thats interesting. It was a tie.")
m = await ctx.send(
embed=yet,
components=[Select(placeholder="Select 1", options=[SelectOption(label="Rock", value="Rock"), SelectOption(label="Paper", value="Paper"), SelectOption(label="Scissors", value="Scissors")])]
,
)
interaction = await bot.wait_for("select_option", check = lambda i: i.component[0].value == "A")
await interaction.respond(content = f"{interaction.component[0].label} selected!")
我导入的内容以及我的机器人是如何定义的:
import os, csv, random, discord, asyncio, pandas, requests, json, traceback
from discord.ext import commands
from dotenv import load_dotenv
from discord_components import DiscordComponents, Button, Select, SelectOption
load_dotenv()
botToken = os.getenv("DiscBotToken")
【问题讨论】:
-
您是否也可以发送代码以说明您定义机器人的位置以及如何和您的导入
-
更新了,希望我给了你正确的信息:)
-
你在代码中的任何地方都做了
DiscordComponents(bot)吗? -
天哪,这立即解决了我的问题。为什么答案那么容易,我没有弄清楚。我真的很感激!
标签: python python-3.x discord discord.py