【问题标题】:Discord.py - sending user input to another channel via the bot (Rewrite)Discord.py - 通过机器人将用户输入发送到另一个频道(重写)
【发布时间】:2021-08-07 20:35:34
【问题描述】:

我正在尝试这样做,以便您可以在命令后从特定通道获取用户输入,然后机器人将用户输入发送到不同的通道。谁能告诉我我犯的任何错误以及如何修复它们,因为我的代码似乎不起作用?我最近才开始使用 discord.py 重写。

import discord
import os
from discord.ext import commands


client = commands.Bot(command_prefix=">")


@client.command()
async def resus(ctx):
  await ctx.send("To reserve a username type - user (your discord tag) (the username you want) (if you want verification)")
  def check(msg):
    return msg.channel.id == 873501773971726346
  
  msg = await client.wait_for("message", check=check)

  if msg.content.lower() == msg.content.lower():
    qwerty = bot.get_channel(873564203535958047)
    await qwerty.send(f"{msg}")
  else:
    await ctx.send("There has been a problem, please try again.")


@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))


client.run(os.getenv('TOKEN'))

【问题讨论】:

  • 请修复缩进,我们应该将您的代码复制并粘贴到 python 文件中并在没有语法/缩进错误的情况下运行它。

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


【解决方案1】:

msg.channel 是一个discord.TextChannel 实例,你正在将它与一个整数进行比较,这绝不是True。您需要改为比较频道 ID:

def check(msg):
    return msg.channel.id == 873501773971726346

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 2021-09-28
    • 2016-05-03
    • 1970-01-01
    • 2021-02-18
    • 2021-04-05
    • 2021-09-09
    相关资源
    最近更新 更多