小编Cal*_*ium的帖子

DiscordJS Canvas 附件未完全发送?

我目前正在为我的机器人使用 Discord.js 和 Node,它以设定的时间间隔发送附件。我面临一个问题,有时附件没有完全加载(它们无限期加载,只有当我点击“打开原件”时,我才能看到图像的前几个像素)。为什么是这样?是不是因为发送附件时附件文件不完整?

将图像添加到文件

async function makeCanvas(img, code, channel) {
  const canvas = createCanvas(900, 1375);
  const ctx = canvas.getContext("2d");
  ctx.fillStyle = "#000000";
  ctx.fillRect(0, 1255, 900, 120);
  let image = await loadImage(img);
  ctx.drawImage(image, 0, -40);
  ctx.font = "bold 100px sans-serif'";
  ctx.textAlign = "center";
  ctx.fillStyle = "#FFFFFF";
  ctx.fillText(`${code}`, 435, 1350);
  const writeable = fs.createWriteStream(`./temp/${channel.id}.png`);
  const readable = canvas.createPNGStream();
  const connection = readable.pipe(writeable);
  return connection.path;
}
Run Code Online (Sandbox Code Playgroud)

发送附件

const imgCode = await applyCodeToImg(url, code, message.channel);
await message.channel.send("A new attachment has appeared!", new Discord.MessageAttachment(imgCode)); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js discord discord.js

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

在嵌套导航器中导航时未定义 route.params?

我正在使用 React Native 和 React Navigation。我试图只让我的屏幕变成一个mode="Modal,但路线PARAMS我通过导航越来越“未定义”有错误时TypeError: undefined is not an object (evaluating 'route.params.title')。为什么会这样,我该如何解决?

我的尝试

const ModalScreen = () => (
  <Modals.Navigator mode="modal">
    <Modals.Screen
      name="Modal"
      component={Modal}
      options={({ route }) => ({
        title: route.params.title,
        headerTransparent: true,
        gestureResponseDistance: {
          vertical: 500,
        },
      })}
    />
  </Modals.Navigator>
);
const MainScreen = () => (
  <Items.Navigator>
    <Items.Screen
      name="Main"
      component={Main}
      options={{ headerShown: false }}
    />
    <Items.Screen name="Modal" component={ModalScreen} />
  </Items.Navigator>
);

// Navigating to Modal in another file.
<TouchableOpacity
  onPress={() =>
    navigation.navigate("Modal", { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native react-navigation react-navigation-stack

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