discord.py - 我在 discord.py 中搜索货币代码有什么问题
问题描述
我需要帮助修复我的代码
@client.command
@commands.cooldown(5, 20, commands.BucketType.user)
async def search(ctx):
await open_account(ctx.author)
user = ctx.author
users = await get_bank_data()
peen = users[str(user.id)]["wallet"]
tu = random.randint(19, 157)
rand = random.choice(hs)
embed54=discord.Embed(title='Search in...', description=f'{rand}, {rand}, {rand}')
embed54.add_footer('Do !beg for money as well!')
await ctx.send(embed=embed54)
await client.wait_for(rand)
def check(m):
return m.author == ctx.author and m.channnel == ctx.channel
embed53=discord.Embed(title='You Found...', description=f'${tu} From {ctx.message}')
await ctx.send(embed=embed53)
fa = tu
peen += fa
为什么它不起作用 SyntaxError: 'await' outside async function 我需要帮助,请它每次都会出错,所以也帮助我,是的 boi
解决方案
Since I don't know what hs
means or how you defined it I omitted the whole thing once and replaced it with a simple number just for my test.
To clarify beforehand: You had errors in creating an embed, in your check
function and in your way of rendering with await
functions and some typos.
This method works fine for me:
@client.command()
@commands.cooldown(5, 20, commands.BucketType.user)
async def search(ctx):
def check(m):
return m.author == ctx.author and m.channel == ctx.message.channel # New check
await open_account(ctx.author)
user = ctx.author
users = await get_bank_data()
hs = # DEFINE WHAT IT IS! <<<
peen = users[str(user.id)]["wallet"]
tu = random.randint(19, 157)
rand = random.choice(hs)
embed54 = discord.Embed(title='Search in...', description=f'{rand}, {rand}, {rand}')
embed54.set_footer(text='Do !beg for money as well!') # SET footer
await ctx.send(embed=embed54)
response = await client.wait_for('message', check=check) # Wait for MESSAGE, add check
if response.content == rand: # I assume you want to get the author say one of the numbers
embed53 = discord.Embed(title='You Found...', description=f'${tu} From {ctx.message.content}')
await ctx.send(embed=embed53)
fa = tu
peen += fa
else: # If the number is not in the embed
await ctx.send("You did not respond correctly.")
What did we do?
- Re-built your check as it is
m.channel
and NOTm.channnel
, just a little typo here - Added a "real" footer, as
embed54.add_footer
does not exist, it isembed54.set_footer(text='', icon_url='')
wait_for
a'message'
from the author of the message and ifrand
, which you have to define as I do not know whaths
is, is not in his answer he will not get whatever you defined. (if
/else
statements)- Replaced
ctx.message
withctx.message.content
as otherwise it will give out a longer "text" than justsearch
! Since there were many mistakes in your code I would recommend to have a closer look at the docs again !
推荐阅读
- c++ - 有没有一种方法可以交叉编译库而无需手动编译每个依赖项?
- java - 为 PropertyValueFactory (Java) 添加前缀
- typescript - 为什么 VSCode 调试器不允许我设置断点?
- haskell - 使用 foldl 删除列表的重复
- javascript - 如何在滚动时隐藏导航栏的 JavaScript 添加淡入淡出效果?
- javascript - 将对象数组复制到有组织的数据结构中
- symfony - 开发与测试在 twig 的 format_currency 输出中有所不同
- c++ - 将引用类型分配给非引用类型
- python - 如何在pyqt5中修复/隐藏“无法枚举家庭警告”?
- mysql - 带有 convert_tz 的 Mysql str_to_date 返回 NULL