因此,我使用此代码发送一条消息,该消息将聊天中发送的表情随机化(Discord),但我想这样做,以便在发送表情时每种表情都不同。例如,如果用户要发送命令,它将发送:1、2、3、4、2、3等。我如何制作它,使每个表情不同。我发现的唯一方法是使每个表情都具有不同的var math.random函数。还有其他方法吗,因为制作另一个var有点长。
const randomemote = [
`:four:`,
`:one:`,
`:two:`,
`:three:`
];
var emotes = randomemote[Math.floor(Math.random()*randomemote.length)];
message.channel.send(`
${emotes}${emotes}${emotes}${emotes}${emotes}
${emotes}${emotes}${emotes}${emotes}${emotes}
${emotes}${emotes}${emotes}${emotes}${emotes}
${emotes}${emotes}${emotes}${emotes}${emotes}
${emotes}${emotes}${emotes}${emotes}${emotes}
`)
答案 0 :(得分:1)
创建一个函数,给定重复次数,该函数可以使随机表情重复多次。
Widget build(BuildContext context) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
child: Container(
decoration: BoxDecoration(
border: new Border(
top: BorderSide(
color: Theme.of(context).primaryColor,
width: 3.0,
)),
//borderRadius: BorderRadius.only(topLeft: const Radius.circular(5.0)),
),
child: makeListTile(widget.flight),
),
);
您还可以创建另一个函数,该函数在给定要打印的行数和每行的表情数的情况下,多次调用const randomemote = [
`:four:`,
`:one:`,
`:two:`,
`:three:`
];
const randEmote = () => randomemote[Math.floor(Math.random()*randomemote.length)];
const multRandEmotes = count => Array.from({ length: count }, randEmote)
.join('');
const strToSend = `
${multRandEmotes(5)}
${multRandEmotes(5)}
${multRandEmotes(5)}
${multRandEmotes(5)}
${multRandEmotes(5)}
`;
console.log(strToSend);
:
multRandEmotes