类型错误:“协程”对象不可调用 HELP PLS

问题描述 投票:0回答:1

我尝试制作一个discord.py机器人,它制作一个在dm中发送消息的按钮

your text
你可以尝试告诉我如何用其他东西做到这一点。

import discord
from discord.ext import commands

TOKEN = ''
PREFIX = '.'
intents = discord.Intents().all()

bot = commands.Bot(command_prefix=PREFIX, intents=intents)

@bot.event
async def on_ready():
   print("bot connected")

@bot.command()
async def code( ctx ):
   await ctx.author.send ( '1234' )
   
class Menu(discord.ui.View):
   def __init__(self):
      super().__init__()
      self.value = None

   @discord.ui.button(label="Code", style=discord.ButtonStyle.green)
   async def menu1(self, interaction:discord.Interaction, button:discord.ui.Button):
      await interaction.user.send()("8888")

@bot.command()
async def menu(ctx):
   view = Menu()
   await ctx.reply(view=view)

bot.run(TOKEN)

我尝试制作一个discord.py机器人,它制作一个在dm中发送消息的按钮

your text
你可以尝试告诉我如何用其他东西做到这一点。

discord.py
1个回答
0
投票

用户没有

.send()
方法。用户有一个
.create_dm()
方法,它创建一个
DMChannel
对象。这个
DMChannel
对象有一个
.send()
方法来在 DM 通道中发送消息。 用这个代替
ctx.author.send('1234')

channel = await ctx.author.create_dm()
await channel.send('1234')
© www.soinside.com 2019 - 2024. All rights reserved.