我需要帮助解决使用discord_API的flutter项目中的一些错误

kulphzqa  于 2023-03-19  发布在  Flutter
关注(0)|答案(1)|浏览(118)

出现以下错误:
命名参数“clientId”是必需的,但没有对应的参数。命名参数“clientSecret”是必需的,但没有对应的参数。命名参数“discordHttpClient”是必需的,但没有对应的参数。命名参数“redirectUri”是必需的,但没有对应的参数。位置参数太多:应为0,但找到1。没有为类型“DiscordClient”定义方法“connect”。没有为类型“DiscordClient”定义方法“disconnect”。没有为类型“DiscordClient”定义方法“getChannel”。
下面是完整的代码:

import 'package:flutter/material.dart';
import 'package:discord_api/discord_api.dart';

const String token = 'sua-chave-de-api-aqui';
const String clientId = 'seu-client-id-aqui';
const String clientSecret = 'seu-client-secret-aqui';
const String redirectUri = 'http://localhost:8080/callback';

void main() async {
  final client = DiscordClient(token);

  await client.connect();

  runApp(MyApp(client));
}

class MyApp extends StatefulWidget {
  final DiscordClient client;

  const MyApp(this.client);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final TextEditingController _controller = TextEditingController();
  final String _channelId = 'id-do-canal-aqui';

  @override
  void dispose() {
    widget.client.disconnect();
    super.dispose();
  }

  void _sendMessage() async {
    final channel = await widget.client.getChannel(_channelId);
    await channel.sendMessage(_controller.text);

    _controller.clear();
  }
}

我什么都试过了,但没有结果。

yacmzcpb

yacmzcpb1#

第一个错误消息告诉您,您的代码无法编译,因为DiscordClient的构造函数需要一些您没有提供的参数。.根据the documentation,您必须如下示例化DiscordClient

final _discordClient = DiscordClient(
  clientId: clientId,
  clientSecret: clientSecret,
  redirectUri: redirectUri,
  discordHttpClient: DiscordDioProvider(clientId: clientId, clientSecret: clientSecret),
);

相关问题