小编Zso*_*ros的帖子

读取文件附件(例如;.txt 文件)-Discord.JS

第二次在 StackOverflow 上发帖,对于任何错误我深表歉意。请多多包涵。

与标题相同;如何读取不和谐附件的内容(假设是一个.txt文件)并打印内容?

我尝试过fs,但不幸的是失败了,我也搜索了文档,但也失败了。

在此输入图像描述

有想法吗?

javascript fs node.js discord discord.js

2
推荐指数
1
解决办法
6711
查看次数

如何让您的 Discord 机器人在您输入命令后收听您的消息?

我正在制作一个 Google Assistant Discord 机器人,但我想知道你的机器人将如何回复你的第二条消息。例如:首先,您说hey google,然后机器人说I'm listening,然后您说what time is it,他说2.40 pm

我做了第一部分,但我不知道如何让它回复第二个参数。有人可以帮我吗?

javascript arguments bots discord discord.js

2
推荐指数
1
解决办法
5390
查看次数

是否可以格式化我们从数组接收到的值以使其成为其他值

我的标题并没有真正解释太多,所以这里有一个解释。

目前,我的 Discord 机器人上有一个命令,可以向我显示 Mojang 的服务器及其状态。

这是代码:

const Discord = require("discord.js");
const { get } = require("https");

module.exports.run = async(bot, message, args) => {
    //const member = message.mentions.members.first() || message.member

    get("https://status.mojang.com/check", (res) => {
        const { statusCode } = res;
        if (statusCode != 200) {
        res.resume;
        }
        res.setEncoding("utf8");
        let rawData = '';
        res.on("data", (chunk) => {
            rawData += chunk;
        });
        res.on("end", () => {
            try {
                const parsedData = JSON.parse(rawData);

                console.log(parsedData[0]);
                console.log(parsedData[1]);

                message.channel.send({
                    embed: {
                        color: 0xe61616,
                        title: `Mojang API …
Run Code Online (Sandbox Code Playgroud)

javascript arrays json node.js discord.js

2
推荐指数
1
解决办法
125
查看次数

如何从 vue 渲染中发出

render()我正在使用 HTML 模板而不是从 HTML 模板渲染组件。我想从我正在渲染的组件中发出一个属性,但我不确定如何在渲染的组件中获取该属性(我将@在 HTML 模板中使用)。

谢谢你!

emit vue.js

1
推荐指数
1
解决办法
2198
查看次数

如何使用 CSS inset 将元素定位在右上角?

而不是toprightCSS 属性,我想用它 inset来定位元素。

例如,以下代码将元素放置在右上角:

.top-right {
  top: 0;
  right: 0;
} 
Run Code Online (Sandbox Code Playgroud)

您将如何使用该inset属性实现相同的目标?我尝试过使用不同的方法,但无法弄清楚。

尽管我在下面的示例中将top和都设置right为 0 inset,但它不起作用:

.top-right {
  inset: 0 0;
}
Run Code Online (Sandbox Code Playgroud)

html css

1
推荐指数
1
解决办法
307
查看次数

有没有办法避免数字到字符串转换和嵌套循环以提高性能?

我刚刚在网上进行了一次编码测试,这个问题真的让我很困扰。我的解决方案是正确的,但因未优化而被拒绝。问题如下:

编写一个combineTheGivenNumber带两个参数的函数:

  1. numArray: 数字[]
  2. num: 一个号码

该函数应该检查所有可能导致数字等于的连接对num并返回它们的计数。

例如,如果numArray= [1, 212, 12, 12]& num= 1212 那么我们将有3from 的返回值combineTheGivenNumber

对如下:

  1. numArray[0]+numArray[1]
  2. numArray[2]+numArray[3]
  3. numArray[3]+numArray[2]

我为此目的编写的函数如下:

function combineTheGivenNumber(numArray, num) {
  //convert all numbers to strings for easy concatenation
  numArray = numArray.map(e => e+'');
  //also convert the `hay` to string for easy comparison
  num = num+'';
  let pairCounts = 0;
  
  // itereate over the array to get pairs
  numArray.forEach((e,i) => {
    numArray.forEach((f,j) => …
Run Code Online (Sandbox Code Playgroud)

javascript optimization performance

1
推荐指数
1
解决办法
205
查看次数

如何在React中获取map函数中的最后一项

我有一组从 CMS 返回给我的数据。我映射每个项目并返回带有相应数据的组件。但是,我需要定位方法.map中函数的最后一项render,因为最后一项需要进行一些修改。

我该怎么做?

return (
  <div>
    {data.body.map((item, i) => {
      console.log(i);
      if (item.type === 'button') {
        return <ButtonComponent color="ffffff" bgColor="4C319D" text={item.text} textAlign="left" id={item.id} />
      }
    })}
  </div>
)
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

1
推荐指数
1
解决办法
8545
查看次数

Discord Slash 命令:发送嵌入时出错

我正在为我的机器人创建一个斜杠命令。所以我尝试了这个

Client.ws.on('INTERACTION_CREATE', async interaction => {
    Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
        type: 4,
        data: {
            content: 'hello world!'
        }
    }})
})
Run Code Online (Sandbox Code Playgroud)

这很好用。
所以我尝试发送嵌入并尝试下面的这些(2)代码

Client.ws.on('INTERACTION_CREATE', async interaction => {
    Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
        type: 4,
        data: {
            content: {
                embed: exampleEmbed
            }
        }
    }})
})
Run Code Online (Sandbox Code Playgroud)

Client.ws.on('INTERACTION_CREATE', async interaction => {
    Client.api.interactions(interaction.id, interaction.token).callback.post({data: {
        type: 4,
        data: {
            embed: exampleEmbed
        }
    }})
})
Run Code Online (Sandbox Code Playgroud)

这些都不起作用。

那么我做错了什么?
或者,如何使用斜杠命令发送嵌入?

编辑:这就是我的定义exampleEmbed

const exampleEmbed = {
    color: 0x0099ff,
    title: 'Hello world',
    thumbnail: {
        url: 'https://i.imgur.com/wSTFkRM.png',
    }, …
Run Code Online (Sandbox Code Playgroud)

javascript node.js discord discord.js

1
推荐指数
2
解决办法
1万
查看次数

Discord.js channels.create 不是构造函数

我一直在制作一个机器人,当成员对消息做出反应时,它会创建一个支持频道。它发送一个嵌入等待反应就好了,但是当我对应该为我创建一个新频道的消息做出反应时,它会抛出一个错误,说Uncaught TypeError: guild.channels.create is not a constructor. 它不会告诉它从哪条线抛出。

这是引发错误的代码块:

} else if(reaction.message.channel.id == supportChannelID){
        console.log('support');
        if(reaction.emoji.name== ''){
            let guild = reaction.message.guild;
            let supportChannel = new guild.channels.create(`Podpora - ${user.username}`)
                type: text,
                supportChannel.overwritePermissions([
                {
                    id: memberRole,
                    deny: ['VIEW_CHANNEL'],
                },
                {
                    id: user.id,
                    allow: ['VIEW_CHANNEL'],
                    allow: ['SEND_MESSAGES'],
                    allow: ['READ_MESSAGE_HISTORY'],
                    allow: ['ATTACH_FILES'],
                },
                ])
            console.log('created channel');
            let supportChannelEmbed = new Discord.MessageEmbed()
                .setColor(1752220)
                .setAuthor("Azuremic", "https://i.imgur.com/m4hkkIj.png")
                .addFields(
                    {name: `Podpora ${user.username}`, value: 'Po?kej na n?koho z Admin Teamu prosím'}
                )
                .setFooter("Reaguj pomocí ? ke smazání …
Run Code Online (Sandbox Code Playgroud)

javascript node.js discord.js

1
推荐指数
1
解决办法
42
查看次数

Discord.js v13:斜线命令重复

这似乎是一个错误,或者我不知道,但我确信这是可以修复的。我的所有斜杠命令都是重复的,第一个是该命令的最新版本,第二个是一些过时的命令。

预览

我假设它与斜杠命令注册有关,所以这里是:

const guild = await client.guilds.cache
            .get("836212492769165363")

        guild.commands.set(arrayOfSlashCommands).then((cmd) => {
          const getRoles = (commandName) => {
            const permissions = arrayOfSlashCommands.find(x => x.name === commandName).userPermissions;

            if(!permissions) return null;
            return guild.roles.cache.filter(x => x.permissions.has(permissions) && !x.managed)
          }

          const fullPermissions = cmd.reduce((accumulator, x) => {
            const roles = getRoles(x.name);
            if(!roles) return accumulator;

            const permissions = roles.reduce((a, v) => {
              return [
                ...a,
                {
                  id: v.id, 
                  type: 'ROLE',
                  permission: true,
                },
              ]
            }, [])
            return [
              ...accumulator,
              {
                id: x.id,
                permissions,
              }
            ]
          }, …
Run Code Online (Sandbox Code Playgroud)

javascript bots node.js discord discord.js

1
推荐指数
2
解决办法
9642
查看次数

只允许使用 React.js 上传一种类型的文件

我在我的应用程序中使用 Ant Design 的上传器。

function beforeUpload(file) {
  const filesFormats = [".doc", ".docx", "application/pdf"];
  console.log(file);
  const isRightFormat = filesFormats.includes(file.type);
  console.log(isRightFormat);
  if (!isRightFormat) {
    message.error("You can only upload pdf and doc files");
    return;
  }
  const isLt2M = file.size / 1024 / 1024 < 2;
  if (!isLt2M) {
    message.error("Image must smaller than 2MB!");
  }
  return isRightFormat && isLt2M;
}

class Avatar extends React.Component {
  state = {
    loading: false
  };

  handleChange = (info) => {
    console.log("info, ", info);
    if (info.file.status === "uploading") { …
Run Code Online (Sandbox Code Playgroud)

reactjs antd

0
推荐指数
1
解决办法
1万
查看次数

如何在 React.js 中基于按钮单击来聚焦元素

我有两个按钮和两个文本框。当我单击按钮 1 时,它应该自动聚焦在文本框 1 上。当我单击按钮二时,它应该自动聚焦在文本框2上。

代码:

import React, { Component } from "react";
import "./styles.css";

class App extends Component {
  handleClick(){
    alert("hi");
  }
  render() {
    return (
      <div className="App">
        <div>
          <button onClick={this.handleClick}>One</button>
          <button onClick={this.handleClick}>Two</button>
        </div>
        <div>
          <input type="text" name="one" id="one" placeholder="one" /> 
        </div>
        <div>
          <input type="text" name="two" id="two" placeholder="two" /> 
        </div>
      </div>
    );
  }
}
export default App;
Run Code Online (Sandbox Code Playgroud)

链接到codesandbox

reactjs

0
推荐指数
1
解决办法
2万
查看次数

使用 discord.js 中的命令禁用机器人

有可能做这样的事情吗?根据我的理解,您应该使用,if (enabled == true)但我不确定如何使用。

javascript node.js discord discord.js

0
推荐指数
1
解决办法
48
查看次数