【问题标题】:ctx.send() isnt sending the message in discord.pyctx.send() 没有在 discord.py 中发送消息
【发布时间】:2020-12-21 07:52:20
【问题描述】:

简单的问题:我有这个代码块,它应该根据我所知道的向我发送一条关于不和谐的消息,但它没有,我也没有收到错误,它只是没有做任何事情。它也没有停止,只是继续跑到无处。代码如下所示:

@bot.command
async def steamfetch(ctx):
    await ctx.send("hi there")
    if Float <= 0.05:
        print('in bracket')
        element2 = driver.find_element_by_xpath('/html/body/div[1]/div[7]/div[2]/div[2]/div[4]/div[1]/div[3]/div[4]/div[4]/div[2]/div[2]/div[2]/span/span[1]')
        Price = element2.text
        print('ready to send')
        await ctx.send(f"Snipe found:\nMag-7 Carbon Fiber Factory New with Float:\n{Float}\n{Price}") 
bot.run('Token')

但是,第一条消息和第二条消息都不做任何事情。该变量肯定小于 0.05,但第一个打印也没有进来。我也尝试过不使用 if 函数,但这也不起作用。我上面有一个async def on_ready: 函数,它有效,所以我认为机器人不是问题
有什么想法吗?

【问题讨论】:

  • 只是@bot.command() 而不是@bot.command

标签: python python-3.x discord.py


【解决方案1】:

我认为您忘记为命令添加前缀:

client = commands.bot(command_prefix = '.')

您可以将. 替换为其他内容

还可以尝试将@bot.command 替换为@client.command()

像这样:

import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '.')

@client.command()
async def steamfetch(ctx):
    await ctx.send("hi there")
    if Float <= 0.05:
    print('in bracket')
    element2 = driver.find_element_by_xpath('/html/body/div[1]/div[7]/div[2]/div[2]/div[4]/div[1]/div[3]/div[4]/div[4]/div[2]/div[2]/div[2]/span/span[1]')
    Price = element2.text
    print('ready to send')
    await ctx.send(f"Snipe found:\nMag-7 Carbon Fiber Factory New with Float:\n{Float}\n{Price}")
client.run('token')

【讨论】:

  • bot.command 和 client.command 更好,但 client.command 是 discord.py 的最新库,但最终,它们应该具有相同的特权。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-07
  • 2021-07-08
  • 2021-10-15
  • 1970-01-01
  • 2020-10-15
  • 1970-01-01
  • 2020-12-03
相关资源
最近更新 更多